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
In python/typeshed#703 a reasonable request was made to expose GenericMeta. While that PR just adds it to the stub for typing.py, we should think about and carefully document what behavior subclasses of GenericMeta can depend on.
In particular, I don't think it should be allowed to write your own version of Generic using GenericMeta as a metaclass -- type checkers aren't expected to understand that. But overriding __new__ and invoking super().__new__(...) should be allowed. I'm not sure about the other methods -- e.g. can a subclass of GenericMeta override __getitem__, __copy__ or __isinstancecheck__? (Assuming they use super().)
Probably we should also discuss whether we need to document all keyword arguments for GenericMeta.__new__. There are tvars, args, origin, extra, and orig_bases. I think we could say something about first three (they correspond to __parameters__, __args__, and __origin__ and these are used by most things in typing).
Concerning the behavior of GenericMeta.__new__ with respect to bases we should probably document the following points:
no plain Generic in bases
Generic[...] should appear in bases only once
if Generic[...] is present, then it should list all type variables that appear in other bases
type erasure: all bases are stripped to furthest __origin__
Some of these points are already discussed in PEP 484, but I think it would be reasonable to also mention them in documentation for typing since they are enforced by the runtime implementation.
Activity
ilevkivskyi commentedon Nov 29, 2016
I think this is a good idea. I would prefer to only document
__new__as public. For example__getitem__could be changed if we decide to allow user defined variadic generics,__instancecheck__behavior may change (e.g. http://bugs.python.org/issue28339), etc.Probably we should also discuss whether we need to document all keyword arguments for
GenericMeta.__new__. There aretvars,args,origin,extra, andorig_bases. I think we could say something about first three (they correspond to__parameters__,__args__, and__origin__and these are used by most things intyping).ilevkivskyi commentedon Nov 29, 2016
Concerning the behavior of
GenericMeta.__new__with respect tobaseswe should probably document the following points:Genericin basesGeneric[...]should appear in bases only onceGeneric[...]is present, then it should list all type variables that appear in other bases__origin__Some of these points are already discussed in PEP 484, but I think it would be reasonable to also mention them in documentation for
typingsince they are enforced by the runtime implementation.gvanrossum commentedon Nov 29, 2016
Make public and document GenericMeta (#340)