-
Notifications
You must be signed in to change notification settings - Fork 155
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
False positive when enum is used in iteration #304
Comments
Thanks for the report! All proposed solutions have in common that they need to find out which variables are defined in the scope of the class. Since Vulture currently has no notion of scope, they are tricky to implement. If you see a solution, I'm all ears :-) |
@jendrikseipp That sounds like an even bigger problem :-) Adding scope information should improve the accuracy quite a bit. Python scoping rules are not very complicated. |
There are some libraries that enrich the abstract syntax tree (on which Vulture operates) with scoping information, but I haven't looked deeper into them. I think that could be a good starting point. |
Can I work on this? |
Sure, happy to see progress here! It might be a good idea to discuss the high level approach though, before you spend time on implementing the details. If you have a high-level plan, I'm happy to discuss it. |
@jendrikseipp looked into this a little more, and wanted to run the current implementation idea by you... Progress thus far:
Based on these findings, here is a high level approach of the solution:
|
Yes, your explanation makes sense and the approach is correct, I'd say. (In the last step, you probably mean "used_variables".) The only thing I'm unsure about is the AST library. Have you compared asttokens with https://github.com/kavigupta/ast_scope and https://github.com/pylint-dev/astroid ? We need to pick one that does the job, is well-maintained and doesn't have too many dependencies. |
Enum classes allow iteration over the class, which returns all enum members. This is often convenient particularly when writing tests. Unfortunately, vulture does not understand this and reports enum members as unused. For example:
produces these errors:
This can be whitelisted, but it's a bit tedious when there are many enum members.
Some ideas on how this can be improved:
list(E)
,tuple(E)
,a, b, c = E
,for e in E
and mark all members as used.__all__
, all members can be considered used?The text was updated successfully, but these errors were encountered: