BERTopic
BERTopic copied to clipboard
Enable ruff rule `UP`
What does this PR do?
Discussion at #2450
Enable the pyupgrade (UP) ruff rule and fix all existing violations.
The main changes are:
- Use PEP 585 lowercase type annotations (
list,dict,tupleinstead ofList,Dict,Tuple):
# before
documents: List[str]
# after
documents: list[str]
- Use PEP 604 union syntax (
X | Yinstead ofUnion[X, Y]):
# before
nr_topics: Union[int, str] | None = None
# after
nr_topics: int | str | None = None
- Minor cleanups: parameterless
super(), f-strings instead of%/.format(), remove redundantopen()modes, remove uselessobjectinheritance.
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?
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.