You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from typing import Type, Optional
class Foo:
pass
def make_foo(cls: Optional[Type[Foo]] = None) -> Foo:
x = Foo if cls is None else cls
reveal_type(x)
return x()
gives the following:
typeofclass.py:10: error: Revealed type is 'builtins.object'
typeofclass.py:11: error: "object" not callable
This example is superficially related to #3487, in that it uses an if/else expression to make mypy perform a type join, but the distinct bug here is that joining Foo (the actual class object) with Type[Foo] should result in Type[Foo], but instead results in object.
This is related to the fact that class objects are typed as callables instead of as Type[Class].
Oddly reversing Foo if cls is None else cls to cls if cls is not None else Foo results in builtin.type instead of object, which is still wrong, but differently wrong.
Using cls or Foo results in Type[Foo].
The text was updated successfully, but these errors were encountered:
This file:
gives the following:
This example is superficially related to #3487, in that it uses an if/else expression to make mypy perform a type join, but the distinct bug here is that joining
Foo
(the actual class object) withType[Foo]
should result inType[Foo]
, but instead results inobject
.This is related to the fact that class objects are typed as callables instead of as
Type[Class]
.Oddly reversing
Foo if cls is None else cls
tocls if cls is not None else Foo
results inbuiltin.type
instead ofobject
, which is still wrong, but differently wrong.Using
cls or Foo
results inType[Foo]
.The text was updated successfully, but these errors were encountered: