Replies: 2 comments 2 replies
-
Specialization is a static type concept, not a runtime concept. Specializations are erased at runtime. Specialization information may be available at runtime in some cases if you happen to know the internals of how Python implements generics, but this won't match static typing in all cases. If your code is relying on this behavior, you're going to run into many problems beyond the issue with For example, if you instantiate the generic class
If I understand your goal correctly, you're trying to use the internal implementation machinery of generics to add runtime specialization information, effectively building |
Beta Was this translation helpful? Give feedback.
-
It indeed is very hacky, but now I'm using EDIT: oops, should use the reply box above but accidentally created a new comment |
Beta Was this translation helpful? Give feedback.
-
Continuation of #5449.
So basically, it seems the definition of "specialize" differs between the type checking and the runtime in class methods; while the class is declared specialized by the static type checkers, the
cls
param in the class method does not hold the type info in the runtime.For example, the code:
The
cls
here doesn't have any accessible type info (got "erased") regardless of the way of calling the method, so the resulting instance ofA
has no type info associated with it as well. I know you would need to use library internal attributes to access them, but my code currently relies on the type info to work correctly.Is it not possible to do this with static type checking right now or am I missing something obvious?
My current ugly workaround to avoid relying on impl. details, but should be irrelavent here
Beta Was this translation helpful? Give feedback.
All reactions