Skip to content

Conversation

@avylove
Copy link
Contributor

@avylove avylove commented Feb 8, 2023

Type of Changes

Type
πŸ› Bug fix
✨ New feature
βœ“ πŸ”¨ Refactoring
πŸ“œ Docs

Description

Deprecates modutils.is_standard_module() and splits functionality into two new functions:

  • modutils.is_stdlib_module()

    • Checks if a module is part of the standard library. Uses sys.stdlib_module_names, which is a frozenset in the Python source. It is generated based on the source code and the logic is maintained upstream. This was introduced in 3.10
    • I backported the logic to 3.7, 3.8, and 3.9 to generate a shim to support those versions.
    • This has several advantages over the previous functionality
      • Faster
      • Not dependent on the runtime environment
      • No need to import the modules
      • No need to traverse the filesystem
      • Works for modules that are platform specific even on other platforms (termios, msvcrt, etc)
  • modutils.module_in_path()

    • Checks if a module is in a specific path or paths
    • Uses logic lifted from is_standard_module()
      • Imports to get file, checks if file is in path

Closes #2012

@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Merging #2015 (b330d40) into main (56a65da) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2015      +/-   ##
==========================================
+ Coverage   92.76%   92.78%   +0.01%     
==========================================
  Files          94       95       +1     
  Lines       10967    10998      +31     
==========================================
+ Hits        10174    10204      +30     
- Misses        793      794       +1     
Flag Coverage Ξ”
linux 92.54% <100.00%> (+0.01%) ⬆️
pypy 88.49% <93.93%> (-0.02%) ⬇️
windows 92.33% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
astroid/_backport_stdlib_names.py 100.00% <100.00%> (ΓΈ)
astroid/manager.py 88.15% <100.00%> (ΓΈ)
astroid/modutils.py 87.32% <100.00%> (+0.53%) ⬆️

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the code and changes. Just some minor comments! This can definitely go in the next release!

@DanielNoord DanielNoord added this to the 2.15.0 milestone Feb 12, 2023
@avylove
Copy link
Contributor Author

avylove commented Feb 12, 2023

I think I addressed all the comments. Please take another look when you get the chance.

@DanielNoord DanielNoord merged commit 55afe5d into pylint-dev:main Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement ✨ Improvement to a component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace modutils.is_standard_module() logic with sys.stdlib_module_names

3 participants