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

420420 end = max(end, child[2])
421421
422422 if pos is not None:
423- yield node, pos, end, parents
423+ yield node, pos, cls._node_end(node, end), parents
424424
425425 @staticmethod
426426 def _node_pos(node, default):
429429 return node.lineno, node.col_offset
430430
431431 @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
432441 def _get_exceptions_for_neighboring_parens(sorted_optional_parens_coords,
433442 tokens):
434443 if len(sorted_optional_parens_coords) < 2:
462471 @staticmethod
463472 def _node_in_parens(parens_coord, pos, end):
464473 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
465476 return open_ <= pos <= end <= close
466477

The check that tells the two apart

failpass·tests/test_redundant_parentheses.py::test_
failpass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[explicit-False]
failpass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[explicit-True]
failpass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[implicit-False]
failpass·tests/test_redundant_parentheses.py::test_parens_in_slice_2_no_end[implicit-True]
failpass·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