Skip to content

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

Merged
cooperlees merged 4 commits intoPyCQA:masterfrom
ichard26:comprehensions-are-also-mutable
Sep 28, 2021
Merged

EHN: also raise B006 for list/dict/set comprehensions#186
cooperlees merged 4 commits intoPyCQA:masterfrom
ichard26:comprehensions-are-also-mutable

Conversation

@ichard26
Copy link
Copy Markdown
Contributor

Fixes GH-184.

@ichard26
Copy link
Copy Markdown
Contributor Author

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

Comment thread bugbear.py Outdated
)
)
B006.mutable_literals = (ast.Dict, ast.List, ast.Set)
B006.mutable_comprehensions = (ast.ListComp, ast.DictComp)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread tests/test_bugbear.py
B006(70, 32),
B008(98, 29),
B008(102, 44),
B006(124, 45 if sys.version_info >= (3, 8) else 46),
Copy link
Copy Markdown
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