Forbid tuples without parenthesis
See original GitHub issueRule request
Thesis
# bad
a = 1, 2
# good
a = (1, 2)
Reasoning
It shocked me to learn that in Python tuples are defined by commas and not parenthesis. This rule request will find a very likely bug that is a = 1,
, a one element tuple. Also it improves readability.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
python - When are parentheses required around a tuple?
The combining of expressions to create a tuple using the comma token is termed an expression_list . The rules of operator precedence do...
Read more >How to Print a Tuple Without Parentheses in Python? - Finxter
You can print a tuple without parentheses by combining the string.join() method on the separator string ', ' with a generator expression to...
Read more >Avoid accidental tuples best practice | CodeReview.doctor
According to the documentation: it is actually the comma which makes a tuple, not the parentheses. The parentheses are optional, except in the...
Read more >Print a tuple without parentheses in Python | bobbyhadz
Use the str.join() method to print a tuple without parentheses, e.g. result = ','.join(my_tuple) . The str.join ...
Read more >Tuples in Python
Visually, tuples are defined with parentheses () instead of square brackets [] like lists. Functionally tuples, unlike lists, are immutable — ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The AST is identical for these two cases:
So you either need:
Yes, it is using tokens: https://github.com/ar4s/flake8_tuple/blob/3d706b0f4ae6a7dda516677031af86a2b72b19c8/flake8_tuple.py#L102-L124