Feature
An example where this currently fails is:
t: type[str|int]
asserttisint# t == int also failsreveal_type(t) # gives type[str] | type[int]
I would like the assertion on line 2 to narrow the type of t to type[int].
More generally, using is on a type should narrow that type.
Here is another use case:
def__eq__(self, obj: object) ->bool:
returntype(self) istype(obj) andself.value==obj.value
Currently, there is an issue that "object has no attribute value".
This can be avoided with
def__eq__(self, obj: object) ->bool:
returntype(self) istype(obj) andself.value==cast(Self, obj).value# orreturnisinstance(obj, type(self)) andisinstance(self, type(obj))andself.value==obj.value
But it would be great if the cast were avoided in this idiomatic check.
I don't know enough about Mypy's implementation to know how this would fit in, but I expect that isinstance and issubclass checks could be extended.
Feature
An example where this currently fails is:
I would like the assertion on line 2 to narrow the type of
ttotype[int].More generally, using
ison atypeshould narrow that type.Here is another use case:
Currently, there is an issue that "object has no attribute value".
This can be avoided with
But it would be great if the cast were avoided in this idiomatic check.
I don't know enough about Mypy's implementation to know how this would fit in, but I expect that
isinstanceandissubclasschecks could be extended.