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
Currently to mark a package or module to be available in a certain Python version, it has to be moved to a specially named directory (e.g. stdlib/3.4). This has a few shortcomings:
Module removals can't be expressed (like macpath in 3.8)
Additions of submodules is awkward and usually has to duplicate multiple files
Platform-availability can't be expressed
I suggest to add a marker inside stub files based on the existing sys.version_info/sys.platform checks to mark the unavailability of a module, in addition to the existing path-based system. This could, for example, look like this:
This might prove hard to implement "correctly", i.e. refuse imports of unavailable modules, but an easy workaround is to print a warning when such a construct is encountered while parsing a file and possibly stop parsing the stub at this point.
Huh, Guido must be psychic. This basically fulfills the use case above, except it can't determine that a module can't be imported at all. But in practice this should not matter. This seems like a feature that would be a good fit for the type stub PEP.
This is mostly moot due to the new typeshed layout, where the VERSIONS file specifies available versions. Only open issue are modules unavailable in some OSes, but that sounds more of a typeshed issue anyway.
Activity
JelleZijlstra commentedon Dec 4, 2018
Mypy landed a similar feature recently (python/mypy#5894).
srittau commentedon Dec 4, 2018
Huh, Guido must be psychic. This basically fulfills the use case above, except it can't determine that a module can't be imported at all. But in practice this should not matter. This seems like a feature that would be a good fit for the type stub PEP.
srittau commentedon Nov 4, 2021
This is mostly moot due to the new typeshed layout, where the
VERSIONSfile specifies available versions. Only open issue are modules unavailable in some OSes, but that sounds more of a typeshed issue anyway.