Skip to content

Enable RUF and PT ruff rules#2520

Merged
mhsmith merged 29 commits intobeeware:mainfrom
NMertsch:enable-RUF-rules
Oct 20, 2025
Merged

Enable RUF and PT ruff rules#2520
mhsmith merged 29 commits intobeeware:mainfrom
NMertsch:enable-RUF-rules

Conversation

@NMertsch
Copy link
Contributor

@NMertsch NMertsch commented Oct 19, 2025

Enable the RUF and PT ruff rule sets and handle all findings.

These changes were not requested. If you don't want them, please just reject the PR. If you want only a subset, or all changes spread over multiple PRs, please let me know.

Here are all code changes:

RUF - ruff-specific rules

  • 1595e70: RUF001 - Label ambiguous non-ASCII characters in code
  • d35c8b3: RUF003 - Normalize or label ambiguous non-ASCII characters in comments
  • 88afbc9: RUF005 - Replace collection concatenations with unpacking
  • fad6a61: RUF012 - Annotate mutable class attributes as immutable (e.g. dict as Mapping)
  • ec3a2d6: RUF013 - Replace x: str = None with x: str | None = None
  • 90c6c33: RUF015 - Replace list(...)[0] with iter(next(...))
  • 2b890ea: RUF019 - Simplify "dict key is missing or empty" checks
  • 08f6b7c: RUF043 - Escape . in Regex patterns
  • 5aacfa8: RUF059 - Prefix unused unpacked variables with underscores
  • d7ff87f: RUF100 - Remove two unused noqa directives

PT - flake8-pytest-style

  • 296fa2a: PT001 - Remove empty parentheses on pytest.fixture calls
  • 29da6fc: PT006 - Use tuple instead of str for pytest.mark.parametrize parameter list
  • a7add3a: PT007 - Use list instead of tuple for pytest.mark.parametrize cases
  • e1661bd: PT011 - Check for error messages in pytest.raises()
  • 563d61c: PT012 - Simplify pytest.raises() blocks
  • 574a4fb: PT014 - Remove duplicate test cases in pytest.mark.parametrize
  • 1479207: PT018 - Split assert ... and ... statements
  • be79a8c: PT022 - Replace yield in pytest fixture without teardown with return

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

RUF013: 'PEP 484 prohibits implicit `Optional'
RUF059: 'Unpacked variable is never used'
RUF005: 'Consider iterable unpacking instead of concatenation'
RUF003: 'Comment contains ambiguous  `’` (RIGHT SINGLE QUOTATION MARK)'
RUF019: 'Unnecessary key check before dictionary access'
RUF015: 'Prefer `next(iter(...))` over single element slice'
RUF001: 'String contains ambiguous `ı` (LATIN SMALL LETTER DOTLESS I)'
RUF043: 'Pattern passed to `match=` contains metacharacters but is neither escaped nor raw'
RUF100: 'Unused `noqa` directive (non-enabled: `E501`)'
RUF012: 'Mutable class attributes should be annotated with `typing.ClassVar`'
@NMertsch NMertsch changed the title Enable RUF ruff rules Enable RUF and RSE ruff rules Oct 19, 2025
@NMertsch NMertsch marked this pull request as draft October 19, 2025 20:53
RSE102: 'Unnecessary parentheses on raised exception'
PT022: 'No teardown in fixture, use `return` instead of `yield`'
PT001: 'Use `@pytest.fixture` over `@pytest.fixture()`'
PT012: '`pytest.raises()` block should contain a single simple statement'
PT018: 'Assertion should be broken down into multiple parts'
PT014: 'Duplicate of test case in `pytest.mark.parametrize`'
PT007: 'Wrong values type in `pytest.mark.parametrize` expected `list` of `tuple`'
PT006: 'Wrong type passed to first argument of `pytest.mark.parametrize`; expected `tuple`'
PT011: '`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception'
@NMertsch NMertsch changed the title Enable RUF and RSE ruff rules Enable RUF, RSE, and PT ruff rules Oct 19, 2025
@NMertsch NMertsch marked this pull request as ready for review October 19, 2025 21:40
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good; however, I'd argue against adding the RSE ruleset. I understand the braces are redundant, but I think the bracket less syntax is confusing unless you fully understand the underlying behavior, as it means the raise doesn't explicitly read as an empty instantiation.

As a general rule, multiple smaller PRs are preferable to one big one; but in this case, just dropping the RSE rule (and related changes) is fine (unless undoing the RSE changes is easier to do in new PRs).

@NMertsch NMertsch changed the title Enable RUF, RSE, and PT ruff rules Enable RUF and PT ruff rules Oct 20, 2025
@NMertsch
Copy link
Contributor Author

in this case, just dropping the RSE rule (and related changes) is fine

Done.

@mhsmith mhsmith merged commit 638f336 into beeware:main Oct 20, 2025
57 checks passed
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.

4 participants