Whole file
robsdedude/flake8-picky-parentheses
The author described this change as “Fix exception for parentheses in slices Py3.9+”. It counts as a record because the checks below fail on the code as it stood at ee7d4ab0f and pass on 485998c8a, with nothing else changed between the two runs.
Fix saved2022-10-25
Sharing licenceApache-2.0 · LICENSE
Change size+12 −1
What the code was meant to do, written into the code itself as a save note
Fix exception for parentheses in slices Py3.9+
The change
| 420 | 420 | end = max(end, child[2]) | |
| 421 | 421 | ||
| 422 | 422 | if pos is not None: | |
| 423 | - | yield node, pos, end, parents | |
| 423 | + | yield node, pos, cls._node_end(node, end), parents | |
| 424 | 424 | ||
| 425 | 425 | @staticmethod | |
| 426 | 426 | def _node_pos(node, default): | |
| ⋯ | |||
| 429 | 429 | return node.lineno, node.col_offset | |
| 430 | 430 | ||
| 431 | 431 | @staticmethod | |
| 432 | + | def _node_end(node, default): | |
| 433 | + | if ( | |
| 434 | + | not hasattr(node, "end_lineno") | |
| 435 | + | or not hasattr(node, "end_col_offset") | |
| 436 | + | ): | |
| 437 | + | return default | |
| 438 | + | return node.end_lineno, node.end_col_offset | |
| 439 | + | ||
| 440 | + | @staticmethod | |
| 432 | 441 | def _get_exceptions_for_neighboring_parens(sorted_optional_parens_coords, | |
| 433 | 442 | tokens): | |
| 434 | 443 | if len(sorted_optional_parens_coords) < 2: | |
| ⋯ | |||
| 462 | 471 | @staticmethod | |
| 463 | 472 | def _node_in_parens(parens_coord, pos, end): | |
| 464 | 473 | open_, _, _, close, _ = parens_coord | |
| 474 | + | close = close[0], close[1] + 1 | |
| 475 | + | # close[1] + 1 to allow the closing parenthesis to be part of the node | |
| 465 | 476 | return open_ <= pos <= end <= close | |
| 466 | 477 | ||
The check that tells the two apart
fail→pass·tests/test_redundant_parentheses.py::test_
fail→pass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[explicit-False]
fail→pass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[explicit-True]
fail→pass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[implicit-False]
fail→pass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[implicit-True]
fail→pass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[no-False]
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 itee7d4ab0fbf0e6c16a2aa4d302a13324ae230ad6
Broken version dated2022-10-10
Moduleflake8_picky_parentheses._redundant_parentheses
Units changedPluginRedundantParentheses
Fingerprint2484bc5292862134
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
- 2022-10-07Python 3.10: fix match/case (#24)