Skip to content

Flexible module availability checks #596

Closed
@srittau

Description

@srittau

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:

if sys.version_info >= (3, 8):
    raise NotImplementedError()
if sys.platform != "win32":
    raise NotImplementedError()

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions