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
importabcimporttyping# Define two base types `ABase` & `BBase` with a similar interface,# that each return a different object type `AValue` & `BValue` from# some method## The object type is also reexposed as a class attribute on the# respective base type for easier access.classAValue:
value: bytesdef__init__(self, value: bytes):
self.value=valueclassABase(metaclass=abc.ABCMeta):
VALUE_T=AValue@abc.abstractmethoddefget_some_value(self) ->AValue: ...
classBValue:
value: strdef__init__(self, value: str):
self.value=valueclassBBase(metaclass=abc.ABCMeta):
VALUE_T=BValue@abc.abstractmethoddefget_some_value(self) ->BValue: ...
# Define generic type over the two defined aboveAnyBase=typing.TypeVar("AnyBase", ABase, BBase)
## HOW WOULD I NAME THE RETURN TYPE IN THE NEXT LINE?## In particular note that the return type could not be just `AnyBase`# (over which we are generic) since we aren't returning *that* type,# but some other type determined by which type `AnyBase` is.defmagic_convert(input: AnyBase) ->AnyBase.VALUE_T: #???returninput.VALUE_T(self.get_some_value().value*2)```
Actual behaviour: There does seem to be anything like AnyBase.VALUE_T available for use in mypy and the given syntax results in both type-time and runtime errors.
Expected behaviour: Some way to do this.
mypy version: 0.730
Python version: 3.7 (Debian)
mypy flags: None
I used some title that probably is close to the real (type theory) name of this feature, feel free to change it to something more fitting. 🙂
The text was updated successfully, but these errors were encountered:
Request Type: Feature Request
Mock-up repro (more detailed mock-up here):
Actual behaviour: There does seem to be anything like
AnyBase.VALUE_T
available for use inmypy
and the given syntax results in both type-time and runtime errors.Expected behaviour: Some way to do this.
mypy version: 0.730
Python version: 3.7 (Debian)
mypy flags: None
I used some title that probably is close to the real (type theory) name of this feature, feel free to change it to something more fitting. 🙂
The text was updated successfully, but these errors were encountered: