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
{{ message }}
Repository navigation
Update the behaviour of the type function for metaclasses #2826
Calling type on a class A yields Type[A], even if A has a metaclass other than type. This leads to incorrectly typechecking interactions with type(A) when when attempting to use metaclass attributes.
Can you give a concrete example?
The interaction with other features might be interesting. Maybe it should work something like this
classM(Generic(T), Type[T]): pass# maybe M(type) is a shorthand for thisT1=TypeVar('T1', bound='A')
classA(metaclass=M):
@classmethoddeffoo(cls: M[T1]) ->T1:
returncls()
reveal_type(A) # E: Revealed type is M[A]classB(A): passreveal_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 M[B] is written Type[B]. Where does this fail?
The culprit in my example seems to be that the type variable T is quantified over type constructors (TypeInfo) and not over types. Perhaps there is a workaround.
(Just thinking out loud).
Activity
TRManderson commentedon Feb 8, 2017
Somewhat related to #2655
elazarg commentedon Feb 8, 2017
Can you give a concrete example?
The interaction with other features might be interesting. Maybe it should work something like this
All of this should be how things work right now, except that
M[B]is writtenType[B]. Where does this fail?elazarg commentedon Feb 8, 2017
I agree it should be possible to write
M[T]for "a type whose metaclass is M".TRManderson commentedon Feb 8, 2017
type(A)isMetawhich definitely has an attributex. Do I need to makeMetasubclassType[T]for it to work?elazarg commentedon Feb 8, 2017
Thanks.
The culprit in my example seems to be that the type variable T is quantified over type constructors (
TypeInfo) and not over types. Perhaps there is a workaround.(Just thinking out loud).
elazarg commentedon Feb 8, 2017
I have a fix for this particular issue, but the WiFi here is not working.
gvanrossum commentedon Mar 29, 2017
Sounds like an updated version of Fermat's claim about his last theorem. :-)
elazarg commentedon Mar 29, 2017
:D
Strip type objects when constructing TypeType (#2832)