mypy icon indicating copy to clipboard operation
mypy copied to clipboard

`issubclass` doesn't narrow metaclasses

Open DetachHead opened this issue 4 years ago • 3 comments

class FooMetaclass(type):
    pass
class Foo(metaclass=FooMetaclass):
    pass

fm: FooMetaclass
reveal_type(fm)  # note: Revealed type is "__main__.FooMetaclass"
if issubclass(fm, Foo):
    reveal_type(fm)  # note: Revealed type is "__main__.FooMetaclass"

https://mypy-play.net/?mypy=master&python=3.10&gist=d03a0fb47ada04cb3e352ed13fc0f58b

DetachHead avatar Dec 07 '21 00:12 DetachHead

Also related:

class A:
    pass

class B:
    pass

t = A
if issubclass(t, B):
    reveal_type(t)  # Should be reported as unreachable, because `t` is never a subtype of `B`

But, this reveals: Revealed type is "def () -> ex.A"

I am going to look into it! Thanks!

Update: no, this is unrelated.

sobolevn avatar Dec 08 '21 10:12 sobolevn

Any progress on this issue ?

montag451 avatar Aug 08 '22 13:08 montag451

Thanks for the ping, I've sent a PR.

sobolevn avatar Aug 08 '22 15:08 sobolevn