Python: Two fixes regarding annotated assignments#6336
Merged
RasmusWL merged 5 commits intoSep 14, 2021
Merged
Conversation
This was a source of false positives for the `py/uninitialized-local-variable` query, as exemplified by the test case.
This is only a temporary fix, as indicated by the TODO comment. The real underlying issue is the fact that `isUnused` is defined in terms of the underlying SSA variables (as these are only created for variables that are actually used), and the fact that annotated assignments are always considered to redefine their targets, which may not actually be the case. Thus, the correct fix would be to change the extractor to _disregard_ mere type annotations for the purposes of figuring out whether an SSA variable should be created or not. However, in the short term the present fix is likely sufficient.
RasmusWL
previously approved these changes
Jul 20, 2021
Member
There was a problem hiding this comment.
Looks good to me.
Should we care to add a test-case such as
def func():
foo = 5
foo: int
return "foo is unused"which I think should be marked by py/unused-local-variable, but probably won't since it now has a type-hint. I don't think it's super important, just thinking out loud.
Contributor
Author
|
Sure, why not. 👍 |
RasmusWL
reviewed
Jul 21, 2021
Member
RasmusWL
left a comment
There was a problem hiding this comment.
thanks 💪 besides performance test, this looks good to me 👍
RasmusWL
approved these changes
Sep 14, 2021
Member
RasmusWL
left a comment
There was a problem hiding this comment.
LGTM 👍 (performance also looks fine)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2652 and a bunch of other FPs seen in the wild.
Should not require a change note.
Will probably need performance testing, although I expect the number of new
DefinitionNodes to be rather low.