Skip to content

Enable ruff rule UP#2474

Open
roli-lpci wants to merge 2 commits intoMaartenGr:masterfrom
roli-lpci:fix/typing-modernize-pep585-604
Open

Enable ruff rule UP#2474
roli-lpci wants to merge 2 commits intoMaartenGr:masterfrom
roli-lpci:fix/typing-modernize-pep585-604

Conversation

@roli-lpci
Copy link

What does this PR do?

Discussion at #2450

Enable the pyupgrade (UP) ruff rule and fix all existing violations.

The main changes are:

  1. Use PEP 585 lowercase type annotations (list, dict, tuple instead of List, Dict, Tuple):
# before documents: List[str] # after documents: list[str]
  1. Use PEP 604 union syntax (X | Y instead of Union[X, Y]):
# before nr_topics: Union[int, str] | None = None # after nr_topics: int | str | None = None
  1. Minor cleanups: parameterless super(), f-strings instead of %/.format(), remove redundant open() modes, remove useless object inheritance.

All safe for Python >=3.10 (project minimum). Follows the same pattern as #2457 (RUF) and #2461 (PD).

Summary:

$ ruff check --statistics 200 UP006 non-pep585-annotation 70 UP035 deprecated-import 62 UP007 non-pep604-annotation-union 3 UP008 super-call-with-parameters 2 UP031 printf-string-formatting 2 UP045 non-pep604-annotation-optional 1 UP004 useless-object-inheritance 1 UP015 redundant-open-modes 1 UP032 f-string 1 UP034 extraneous-parentheses 

Refs #2450

Before submitting

  • This PR fixes a typo or improves the docs (if yes, ignore all other checks!).
  • Did you read the contributor guideline?
  • Was this discussed/approved via a Github issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes (if applicable)?
  • Did you write any new necessary tests?
roli-lpci and others added 2 commits February 25, 2026 03:31
Enable the pyupgrade (`UP`) rule and apply all autofixes. Refs MaartenGr#2450
…otation The `pipeline` (lowercase) is a factory function from transformers, not a type. PEP 604 `str | pipeline` crashes at runtime on Python 3.10+ because the `|` operator requires both operands to be actual types. `Pipeline` (uppercase, from transformers.pipelines.base) is the correct class type. Same class of bug as the `str | callable` fix — mechanical pyupgrade conversion exposing latent type annotation errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@roli-lpci
Copy link
Author

Hi @MaartenGr — CI is fully green across Python 3.10–3.13. Let me know if you'd like any changes or have questions about the approach.

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

Labels

None yet

1 participant