fix(b909): Fix false positive affecting containers of mutables#469
fix(b909): Fix false positive affecting containers of mutables#469cooperlees merged 3 commits intoPyCQA:mainfrom
Conversation
The false positives occurred when trying to edit a dictionary while
iterating over a list of dictionaries:
```
lst: list[dict] = [{}, {}, {}]
for dic in lst:
dic["key"] = False # was false positive - fixed now
```
|
With this patch flake8 complains about the following construct in my code: which is safe to do, because it doesn't add or remove any keys. At least as far as I understand, please correct me if I am wrong. |
|
Thanks for this. What's the plan, did you want to add this fix or do you have more plans for this PR? |
|
I'd be happy to add the fix for for key in my_dictionary:
my_dictionary[key] = Trueat the time I opened the draft PR I wasn't 100% sure this is desired, but judging from the discussions in #467 and the 👍 on henzef comment it seems like this is something we want. I'll hopefully get around to adding this later today. |
These changes allow the following:
```
some_dict = {"foo": "bar"}
for key in some_dict:
some_dict[key] = 3 # no error (previously error'd)
```
Turns out, that the slice type was changed in python 3.9. > Changed in version 3.9: Simple indices are represented by their value, > extended slices are represented as tuples. from https://docs.python.org/3/library/ast.html#module-ast
|
This is ready now 🙂 FYI: tested it with both |
|
No false positives (or true positives :D) in my codebase either. Thanks for the quick fix! |
cooperlees
left a comment
There was a problem hiding this comment.
Thanks for the quick fix with great test coverage! I really appreciate great contributors like yourself.
|
|
||
|
|
||
| def _tansform_slice_to_py39(slice: ast.Slice) -> ast.Slice | ast.Name: | ||
| """Transform a py38 style slice to a py39 style slice. |
There was a problem hiding this comment.
TIL - Thanks for this.
The false positives occurred when trying to edit a dictionary while iterating over a list of dictionaries: