Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace isort by native functionality to identify Python's stdlib modules #26

Open
Nour-Mws opened this issue Dec 26, 2022 · 1 comment
Labels
later P4 unimportant: consider wontfix or other priority parsing-imports

Comments

@Nour-Mws
Copy link
Collaborator

This issue is created to address a discussion in the comments of PR #8.
We're currently using the place_module function from the isort library to assess whether an imported dependency is part of Python's stdlib.
It turns out that isort has a static list of stdlib modules for each Python version. And on further digging in the isort code, @jherland found out that the way these lists are compiled is based on non documented features:

I followed your above link, and looked at the files themselves, which led me to the script that isort uses to make those files, and it's is even more horrible: There seems to be an objects.inv file available from python.org for each release (e.g. https://docs.python.org/3.7/objects.inv), but it's in some weird undocumented partially zlib-compressed format that is decoded by some utility inside Sphinx (a tool for generating API documentation). Yuck...
(edit: more information here: https://sphobjinv.readthedocs.io/en/stable/syntax.html)

Proposed solution

To replace the above isort function with native code, we could use sys.stdlib_module_names in Python >=v3.10, and keep hardcoded lists of stdlib modules for versions 3.7, 3.8 and 3.9.

@jherland
Copy link
Member

jherland commented Mar 1, 2023

Reclassified this issue as considerably less important (consider even wontfix): Since we created this issue we have come to rely more, not less, on isort's classification of import statements. If we are to drop isort as a dependency, it must come with additional benefits/rationale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
later P4 unimportant: consider wontfix or other priority parsing-imports
Projects
None yet
Development

No branches or pull requests

2 participants