I have some points in legacy code (python library: music21) that uses a lot of overloading and Generic variables to show/typecheck that all subelements in a t.Sequence belong to a particular type. There are a lot of @overload decorators to show how different attributes can return different values. At this point the functions work as they should, but a number of PRs in the past have broken the introspection that other devs require.
The code is extensively tested, but the inferred types by checkers such as mypy and PyCharm are not. Is there a way to run testing on inferred types? Something like:
SomeClassType = typing.TypeVar('SomeClassType', bound='SomeClass')
class SomeClass:
pass
class DerivedClass(SomeClass):
pass
class MyIter(typing.Sequence[typing.Type[SomeClassType]]):
def __init__(self, classType: typing.Type[SomeClassType]):
self.classType = classType
# ------- type_checks.py...
derived_iterator = MyIter(DerivedClass)
# this is the line that I don't know exists...
typing_utilities.assert_reveal_type_eq(derived_iterator,
MyIter[DerivedClass])
# or as a string 'MyIter[DerivedClass]'
mypy's reveal_type seems like it would be helpful here, but I can't seem to find any integration into a testing system, etc. Thanks!