BERTopic icon indicating copy to clipboard operation
BERTopic copied to clipboard

Enable ruff rule `UP`

Open roli-lpci opened this issue 9 months ago • 1 comments

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!).
  • [x] Did you read the contributor guideline?
  • [x] 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 avatar Feb 25 '26 11:02 roli-lpci

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.

roli-lpci avatar Feb 26 '26 08:02 roli-lpci