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

EHN: also raise B006 for list/dict/set comprehensions #186

Merged
merged 4 commits into from Sep 28, 2021

Conversation

ichard26
Copy link
Contributor

Fixes GH-184.

@ichard26
Copy link
Contributor Author

oh bloody hell, there's AST differences on Python 3.7 and below >.<

bugbear.py Outdated
@@ -653,6 +655,7 @@ def visit(self, node):
)
)
B006.mutable_literals = (ast.Dict, ast.List, ast.Set)
B006.mutable_comprehensions = (ast.ListComp, ast.DictComp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think set comprehensions ({x for x in y}) is also suitable in this context

Suggested change
B006.mutable_comprehensions = (ast.ListComp, ast.DictComp)
B006.mutable_comprehensions = (ast.ListComp, ast.DictComp, ast.SetComp)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I knew I was forgetting something, thanks for noticing I'll fix it soon once I get back to my computer at home.

@ichard26 ichard26 changed the title EHN: also raise B006 for list/dict comprehensions EHN: also raise B006 for list/dict/set comprehensions Sep 18, 2021
Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks Mr @ichard26 :D

@@ -103,6 +103,8 @@ def test_b006_b008(self):
B006(70, 32),
B008(98, 29),
B008(102, 44),
B006(124, 45 if sys.version_info >= (3, 8) else 46),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree lets only care for newer versions ...

@cooperlees cooperlees merged commit d4e1350 into PyCQA:master Sep 28, 2021
@ichard26 ichard26 deleted the comprehensions-are-also-mutable branch October 1, 2021 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

B006 not raised for list comprehension
3 participants