Skip to content

class decorators changing class type cause wrong errors #3483

@ojii

Description

@ojii
from typing import Type

class A:
    pass

def deco(cls) -> Type[A]:
    return A

@deco
class B:
    pass

def func(cls: Type[A]):
    assert cls is A

func(B)

Running mypy on that code causes this error:

hoge.py:16: error: Argument 1 to "func" has incompatible type "B"; expected Type[A]

mypy version is mypy 0.511-88e8ef28be2465d1693ace4d39cd422987a97220-dirty.

I would expect it to correctly detect the type of B.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions