Skip to content

Generic ClassVar Type failing #5144

Description

@alanhdu

With mypy 0.600 (and the latest master eb1bb064d707ce05735ff6795df82126e75ea6ea), running mypy on

from typing import ClassVar, Type, Generic, TypeVar

_T = TypeVar('_T')

class Array(Generic[_T]):
    _length_: ClassVar[int]
    _type_: ClassVar[Type[_T]]

def generate() -> Type[Array[float]]:
    pass

generate()._type_(3)

fails with

test.py:12: error: Too many arguments for "object"

instead of allowing this to construct a float.

The original use-case here is in the ctypes stubs, where mypy fails to derive the type of (ctypes.c_float * 5)._type_ -- see:

https://github.com/python/typeshed/blob/9ec6d476c44729ea84e9cafde9c5a77610451b0c/stdlib/2and3/ctypes/__init__.pyi#L248-L250

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions