Continuing from yesterday, when I was looking into the attribute __origin__
, I found a PEP called PEP 560 --Core support for typing module and generic types. I arrived at. This PEP has been around since 3.7, so it's an implementation that already exists and can be touched.
Typing
module performancetyping
module__class_getitem__
and __mro_entries__
__class_getitem__
__Getitem__
for class objects__mro_entries__
__mro_entries__
typing._GenericAlias
__mro_entries__
ofList [int]
returns list
, so it behaves as a subclass of list
at runtime.__orig_base__
, and resolved inherited classes are stored in __base__
typing._GenericAlias
typing
module.__origin__
, which was a punch line that was a private attribute to realize __mro_entries__
.__class_getitem__
well, it will be worth hacking.Recommended Posts