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

Option to record and report classes and imports not used at runtime #1757

Open
Zeckie opened this issue Mar 25, 2024 · 1 comment
Open

Option to record and report classes and imports not used at runtime #1757

Zeckie opened this issue Mar 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Zeckie
Copy link

Zeckie commented Mar 25, 2024

A project I'm working on is quite large - has a lot of modules (so lots of imports) and a lot of dataclasses. The dataclasses (or other classes that do not contain their own methods) and their fields show as 100% covered if the module containing them was loaded, whether the classes / fields are used or not.

This can also happen with imports - the import is run, and the target module loaded, so coverage records them as covered. However, nothing actually used the module / functions / classes that were imported.

Describe the solution you'd like

  • A new option, similar to branch coverage, that collects the extra details at runtime (whether the class is instantiated, and which fields are accessed, which imports are used)
  • Highlight unused items in reports, similar to how missing branches are shown

Describe alternatives you've considered
Static checkers can sometimes find unused code, such as imports, but they usually assume that all functions / methods / branches are called, and do not report classes as unused if they are public and so could be used by another module.

Functions / methods could be included too, but I don't think that is necessary as the coverage of code within them is recorded.

Additional context
There are other things in python that behave in a similar way (are defined, given a name, and later accessed by that name) such as global variables.

@Zeckie Zeckie added enhancement New feature or request needs triage labels Mar 25, 2024
@nedbat
Copy link
Owner

nedbat commented Mar 26, 2024

I can see why this would be useful, but I don't see a way to collect that information.

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

No branches or pull requests

2 participants