Skip to content

Add validation for --line-ranges values#5107

Open
avasis-ai wants to merge 1 commit intopsf:mainfrom
avasis-ai:fix-validate-line-ranges
Open

Add validation for --line-ranges values#5107
avasis-ai wants to merge 1 commit intopsf:mainfrom
avasis-ai:fix-validate-line-ranges

Conversation

@avasis-ai
Copy link
Copy Markdown

Summary

The parse_line_ranges function previously accepted invalid ranges without raising errors:

  • "5-3" where START > END
  • "0-5" or "-1-5" with non-positive line numbers

This adds validation to raise a clear ValueError with a descriptive message when invalid ranges are provided, instead of silently accepting them and producing unexpected formatting behavior.

Test Plan

Added test_parse_line_ranges_valid and test_parse_line_ranges_invalid parametrized tests in tests/test_ranges.py covering:

  • Valid ranges: single, same start/end, multiple ranges
  • Invalid ranges: reversed (start > end), zero, negative

The parse_line_ranges function previously accepted invalid ranges like
'5-3' (start > end) or '0-5' (non-positive line numbers) without
raising an error. This adds proper validation with clear error messages.
@cobaltt7
Copy link
Copy Markdown
Collaborator

Thanks @avasis-ai! Please add a changelog entry and add types to the tests.

@github-actions
Copy link
Copy Markdown
Contributor

diff-shades results comparing this PR (4adf522) to main (35921ac):

--preview style: no changes

--stable style: no changes


What is this? | Workflow run | diff-shades documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants