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
Specifically, it would be nice if there was a keyword Instance such that Instance[Type[_T]] is equivalent to _T
I'm thinking about this mostly in the context of working with metaclasses.
Suppose I have a class with a class method that creates an instance of the class written so it can be reused by subclasses. This can be typed in the following way:
I think it is debatable where the best place to discuss this is. It could be done at https://github.com/python/typing/issues but it is plausible to do it here since it could start as an extension?
This feature is desirable because, as far as I know, there's no way to have a union of instances easily.
classA: ...
classB: ...
TypeOfTypes: Union[A, B] # -> Type[A] | Type[B]# how do I get a union of instances without instantiate classes?TypeOfInstances: Union[A(), B()] # -> A | B
To solve the above problem, we have to figure out if an instance is unique value type. I.e. is Union[A(), A()] == Union[A()]?
Specifically, it would be nice if there was a keyword
Instance
such thatInstance[Type[_T]]
is equivalent to_T
I'm thinking about this mostly in the context of working with metaclasses.
Suppose I have a class with a class method that creates an instance of the class written so it can be reused by subclasses. This can be typed in the following way:
And this is automatically usable by subclasses.
What I want is an
Instance
type such that I can correctly type the same logic defined within a metaclass like so:As far as I can tell, there's no way to correctly annotate this
The text was updated successfully, but these errors were encountered: