Whole file

robsdedude/flake8-picky-parentheses

The author described this change as Python 3.10: fix match/case (#24). It counts as a record because the checks below fail on the code as it stood at d2f530a2a and pass on 1384f6f9e, with nothing else changed between the two runs.

Fix saved2022-10-07
Sharing licenceApache-2.0 · LICENSE
Change size+21 3

What the code was meant to do, written into the code itself as a save note

Python 3.10: fix match/case (#24)

The change

1818 "elif": "if True:\n pass\n",
1919 "except": "try:\n pass\n",
2020 "finally": "try:\n pass\n",
21+ "case": "match _:\n ",
2122 }
2223
24+AST_FIX_SPECIAL_BODIES = {
25+ "match": "\n case _:\n pass",
26+}
27+
2328 IGNORED_TYPES_FOR_PARENS = {
2429 tokenize.NL,
2530 tokenize.COMMENT,
191196 line += "\ndef f():"
192197 needs_body = True
193198 if needs_body:
194- line += "\n pass"
199+ keyword = line.strip().split()[0]
200+ line += AST_FIX_SPECIAL_BODIES.get(keyword, "\n pass")
195201 if ast_fix_prefix:
202+ extra_indent = ast_fix_prefix.rsplit("\n", 1)[-1]
203+ if extra_indent.strip():
204+ extra_indent = "" # contains not only whitespace
205+ if extra_indent:
206+ line = "\n".join(extra_indent + s for s in line.split("\n"))
207+ column_offset -= len(extra_indent)
208+ ast_fix_prefix = ast_fix_prefix[:-len(extra_indent)]
196209 line = ast_fix_prefix + line
197- line_offset += ast_fix_prefix.count("\n")
198- column_offset += len(ast_fix_prefix.rsplit("\n", 1)[-1])
210+ line_offset -= ast_fix_prefix.count("\n")
199211 return LogicalLine(
200212 line=line,
201213 line_offset=line_offset,
343355 and isinstance(parents[0], ast.arguments)
344356 and node in parents[0].defaults
345357 and pos[0] != end[0]
358+ ):
359+ rewrite_buffer = ProblemRewrite(parens_coord.open_, None)
360+ last_exception_node = node
361+ elif (
362+ sys.version_info >= (3, 10)
363+ and isinstance(node, ast.MatchSequence)
346364 ):
347365 rewrite_buffer = ProblemRewrite(parens_coord.open_, None)
348366 last_exception_node = node

The check that tells the two apart

failpass·tests/test_redundant_parentheses.py::test_match_case[(foo
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-((a))-case_problem_columns10]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-((a,))-case_problem_columns11]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-((a,),)-case_problem_columns12]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-([a,
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-(a)-case_problem_columns1]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-(a,
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-(a,)-case_problem_columns3]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-[(a,
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-[a,
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-[a]-case_problem_columns4]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-a,
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-a,-case_problem_columns2]
failpass·tests/test_redundant_parentheses.py::test_match_case[(foo)-match_problem_columns1-a-case_problem_columns0]
failpass·tests/test_redundant_parentheses.py::test_match_case[foo
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-((a))-case_problem_columns10]
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-((a,))-case_problem_columns11]
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-((a,),)-case_problem_columns12]
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-([a,
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-(a)-case_problem_columns1]
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-(a,
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-(a,)-case_problem_columns3]
failpass·tests/test_redundant_parentheses.py::test_match_case[foo-match_problem_columns0-[(a,

Check file tests/test_redundant_parentheses.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itd2f530a2a846e8cf454015d75df10c9bf79613bf
Broken version dated2022-10-07
Moduleflake8_picky_parentheses._redundant_parentheses
Units changedPluginRedundantParentheses
Fingerprint73e437afff44109f
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in robsdedude/flake8-picky-parentheses