adamchainz / flake8-comprehensions

❄️ A flake8 plugin to help you write better list/set/dict comprehensions.
MIT License
465 stars 23 forks source link

Tuple in Python is not indicated by parenthesis! #566

Closed olorin37 closed 7 months ago

olorin37 commented 7 months ago

Python Version

No response

flake8 Version

No response

Package Version

No response

Description

C408: Unnecessary <dict/list/tuple> call - rewrite as a literal. It's slower to call e.g. dict() than using the empty literal, because the name dict must be looked up in the global scope in case it has been rebound. Same for the other two basic types here. For example:

Rewrite dict() as {} Rewrite dict(a=1, b=2) as {"a": 1, "b": 2} Rewrite list() as [] Rewrite tuple() as ()

Are you really proposing to represent tuple as (), but for Python it is not right because the comma is an tuple indicator foo, bar this is a tuple or singular one something, and adding parenthesis only adds readability, but it is not syntactically required: (foo, bar) and (something,).

olorin37 commented 7 months ago

OK, () is a literal for empty tuple, I missed that. So, sorry, my issue is not relevant, closing.