Skip to content

error: Missing type parameters for generic type "array" #13942

Description

@sg495

Bug Report

Mypy strict mode complains if a type parameter is omitted when using the built-in array type in an annotation, while Python raises TypeError if a type parameter is included. Mypy only complains in strict mode.

To Reproduce

from array import array
x: array = array("L")      # Mypy error: Missing type parameters for generic type "array"
y: array[int] = array("L") # TypeError: 'type' object is not subscriptable

Expected Behavior

Mypy strict mode should not complain about a missing generic type parameter (since Python does not allow it).

Actual Behavior

array-mypy.py:2: error: Missing type parameters for generic type "array"

Possible Workaround

from array import array
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    IntArray = array[int]
else:
    IntArray = array

x: IntArray = array("L")

Your Environment

  • Mypy version used: mypy 0.982 (compiled: yes)
  • Mypy command-line flags: mypy --strict
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.9.13

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions