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

Mark imports in __all__ as used #282

Merged

Conversation

kreathon
Copy link
Contributor

@kreathon kreathon commented Jun 30, 2022

At the moment, symbols that are referenced in string form in the __all__ variable assignment are not marked as used.

Example

# Currently, 'Bar' would be marked as unused.
from foo import Bar

__all__ = ["Bar"]

Implementation

Add visit_Assign to cover assignments of the following form:

# Default case
__all__ = ["A"]

# Tuples are also tolerated
__all__ = ("B", )

Limitations

The implementation cannot cover dynamic definitions e.g.:

a = ["A"]
__all__ = a

Related Issue

This PR is addressing the issue #172.

Checklist:

  • I have updated the documentation in the README.md file or my changes don't require an update.
  • I have added an entry in CHANGELOG.md.
  • I have added or adapted tests to cover my changes.
  • I have run tox -e fix-style to format my code and checked the result with tox -e style.

@codecov-commenter
Copy link

codecov-commenter commented Jun 30, 2022

Codecov Report

Merging #282 (118eae2) into master (34e93b0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #282   +/-   ##
=======================================
  Coverage   99.37%   99.38%           
=======================================
  Files          19       19           
  Lines         638      648   +10     
=======================================
+ Hits          634      644   +10     
  Misses          4        4           
Impacted Files Coverage Δ
vulture/core.py 99.39% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34e93b0...118eae2. Read the comment docs.

Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

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

Code looks great, thanks! I only have one suggestion, see below. And I was wondering if we should add more tests to cover edge cases such as ignoring code like the following import my_module; my_module.__all__ = ["Foo"]. What do you think?

vulture/core.py Show resolved Hide resolved
Co-authored-by: Jendrik Seipp <jendrikseipp@gmail.com>
@kreathon
Copy link
Contributor Author

kreathon commented Jul 2, 2022

Thank you for your feedback.

I am going to add a few more test cases (also to increase the branch coverage).

@kreathon kreathon requested a review from jendrikseipp July 2, 2022 13:05
@jendrikseipp jendrikseipp merged commit 906ddc0 into jendrikseipp:master Jul 3, 2022
@jendrikseipp
Copy link
Owner

I agree about the readability, but let's go with that version anyway. Thanks for your great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants