New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the behaviour of the type
function for metaclasses
#2826
Comments
Somewhat related to #2655 |
Can you give a concrete example? class M(Generic(T), Type[T]): pass # maybe M(type) is a shorthand for this
T1 = TypeVar('T1', bound='A')
class A(metaclass=M):
@classmethod
def foo(cls: M[T1]) -> T1:
return cls()
reveal_type(A) # E: Revealed type is M[A]
class B(A): pass
reveal_type(B) # E: Revealed type is M[B]
reveal_type(B.foo()) # E: Revealed type is B All of this should be how things work right now, except that |
I agree it should be possible to write |
class Meta(type):
x = 1
class A(metaclass=Meta): pass
print(type(A).x) # test2826.py:6: error: Type[] has no attribute "x"
|
Thanks. The culprit in my example seems to be that the type variable T is quantified over type constructors ( |
I have a fix for this particular issue, but the WiFi here is not working. |
Sounds like an updated version of Fermat's claim about his last theorem. :-) |
:D |
Calling
type
on a classA
yieldsType[A]
, even ifA
has a metaclass other thantype
. This leads to incorrectly typechecking interactions withtype(A)
when when attempting to use metaclass attributes.The text was updated successfully, but these errors were encountered: