Hi all,
I’ve encountered a weird issue with inspect.getmembers()
and would like some help.
Background:
I’ve been adding type hints to a project. One of my classes is a generic container, so I made a type variable _T = TypeVar('_T')
so I could write class MyContainer(Deque[_T])
and not export the variable from the module.
Problem:
There is a test that uses importlib
and inspect
to make sure only the public API is exported.
For some reason in Python >= 3.7, inspect.getmembers()
shows _T
as one of the exports despite the leading underscore and despite __all__
excluding _T
. This is causing the test fail.
A simplified example and results can be seen here:
What changed between 3.6 and 3.7? Am I using inspect.getmembers()
incorrectly?
Thanks.