Skip to content

Generic ClassVar Type failing #5144

Open
@alanhdu

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions