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

Add import-based submodule detection for preferred-modules #8186

Merged
merged 14 commits into from
Feb 8, 2023
Merged

Add import-based submodule detection for preferred-modules #8186

merged 14 commits into from
Feb 8, 2023

Conversation

d33bs
Copy link
Contributor

@d33bs d33bs commented Feb 4, 2023

Type of Changes

Type
✨ New feature

Description

This PR adds new functionality with preferred-modules configuration to detect submodules (along with relevant documentation and tests). The focus was intended to enhance the existing design via the imports.py without losing the original functionality.

I very much appreciate any comments or suggestions towards improving the work in this PR!

Note: I feel that #7957 may still need more work to close beyond this change to possibly detect submodule implementation when a "parent" module has been imported (without a direct submodule import statement to reference). It felt that non-import-specific submodule detection might need to be referenced or implemented outside of imports.py but I wasn't sure exactly where this would fit. Thank you in advance for any thoughts or feedback on this topic specifically!

Refs #7957

@github-actions

This comment has been minimized.

@DanielNoord
Copy link
Collaborator

@d33bs Do you need help investigating the failing test case?

@d33bs
Copy link
Contributor Author

d33bs commented Feb 5, 2023

Thank you @DanielNoord - yes, I may need help here. I am able to see there's something expected by perhaps the message in testdata but I'm not sure how to fix. I'm wondering but not sure if the change for items which could include . in the module name could have triggered this.

@DanielNoord
Copy link
Collaborator

Thank you @DanielNoord - yes, I may need help here. I am able to see there's something expected by perhaps the message in testdata but I'm not sure how to fix. I'm wondering but not sure if the change for items which could include . in the module name could have triggered this.

The issue is in https://github.com/PyCQA/pylint/blob/8d13dbe9d82da64f21c5a62b7c16d2332839a346/tests/functional/p/preferred_module.py#L6

The file indicates that we expect to raise a message on line 5, but with this PR we no longer do. You could try and run only that test and debug why there is a change in behaviour.

@codecov
Copy link

codecov bot commented Feb 5, 2023

Codecov Report

Merging #8186 (b056002) into main (af555ed) will decrease coverage by 0.09%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8186      +/-   ##
==========================================
- Coverage   95.53%   95.45%   -0.09%     
==========================================
  Files         177      177              
  Lines       18619    18650      +31     
==========================================
+ Hits        17788    17802      +14     
- Misses        831      848      +17     
Impacted Files Coverage Δ
pylint/checkers/imports.py 94.33% <100.00%> (+0.04%) ⬆️
pylint/testutils/_primer/package_to_lint.py 76.81% <0.00%> (-23.19%) ⬇️
pylint/checkers/variables.py 97.29% <0.00%> (-0.09%) ⬇️
pylint/checkers/base/basic_checker.py 97.87% <0.00%> (-0.03%) ⬇️
pylint/lint/utils.py 96.00% <0.00%> (ø)
pylint/checkers/base/basic_error_checker.py 95.51% <0.00%> (ø)
pylint/checkers/refactoring/refactoring_checker.py 98.33% <0.00%> (ø)
...int/checkers/refactoring/recommendation_checker.py 96.41% <0.00%> (+0.05%) ⬆️
pylint/checkers/utils.py 95.83% <0.00%> (+0.06%) ⬆️

@d33bs
Copy link
Contributor Author

d33bs commented Feb 5, 2023

Thank you @DanielNoord, this was helpful! I changed the functionality to acknowledge the existing functional test for preferred-modules.

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.

Glad to see you figured it out! The pylint failure can be solved by adding some wordt to our internal dictionary.

Really like this change itself!

tests/checkers/unittest_imports.py Show resolved Hide resolved
tests/checkers/unittest_imports.py Show resolved Hide resolved
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

DanielNoord
DanielNoord previously approved these changes Feb 7, 2023
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.

Thanks @d33bs!

@Pierre-Sassoulas Do you want to review as well?

@github-actions

This comment has been minimized.

pylint/checkers/imports.py Outdated Show resolved Hide resolved
pylint/checkers/imports.py Outdated Show resolved Hide resolved
tests/checkers/unittest_imports.py Outdated Show resolved Hide resolved
@Pierre-Sassoulas
Copy link
Member

Thank you for working on this @d33bs, this bug has been opened for a loooong time !

@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Feb 7, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.0 milestone Feb 7, 2023
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
@d33bs
Copy link
Contributor Author

d33bs commented Feb 8, 2023

Thank you @Pierre-Sassoulas for the review and suggestions! I've applied the changes you suggested and also added two missing asserts for one of the test cases. Please let me know if I may add or update anything.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2023

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit b056002

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Great ! The strange comment I made previously about the issue being opened "for a long time" is because I mistaken that with #5 (Looks similar, let us know if this is the same kind of issue :)

@ssbarnea
Copy link
Contributor

I have reasons to believe that this change introduced a major regression, filed at #8453

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.

4 participants