-
Notifications
You must be signed in to change notification settings - Fork 179
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
Detect unused annotations in functions #668
Conversation
@@ -1208,6 +1219,7 @@ def handleNodeLoad(self, node): | |||
|
|||
binding = scope.get(name, None) | |||
if isinstance(binding, Annotation) and not self._in_postponed_annotation: | |||
scope[name].used = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i only really need this to be truthy, but should i define it as a tuple, like in the try
below?
988943b
to
60051d2
Compare
60051d2
to
93d88be
Compare
pyflakes/checker.py
Outdated
@@ -600,6 +600,17 @@ def unusedAssignments(self): | |||
isinstance(binding, Assignment)): | |||
yield name, binding | |||
|
|||
def unusedAnnotations(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the camel case is legacy code -- new stuff uses snake case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt awkward having unused_annotations
be snake case while unusedAssignments
was pascal case, so I made them both snake case
pyflakes/checker.py
Outdated
name not in self.globals and | ||
not self.usesLocals and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is copied from above, but are these still relevant? does annotating a global do anything? does locals()
include annotated-only things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah I like your point. Seems like it can be simpler, yet still do what we need?
pyflakes/messages.py
Outdated
self.message_args = (names,) | ||
|
||
|
||
class ReturnWithArgsInsideGenerator(Message): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge conflict was resolved incorrectly it looks like
@@ -356,18 +356,24 @@ def test_unused_annotation(self): | |||
class Cls: | |||
y: int | |||
''') | |||
# TODO: this should print a UnusedVariable message | |||
# This should print an UnusedAnnotation message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can just delete the comment now \o/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #546