Skip to content

Conversation

@vincentmacri
Copy link
Member

@vincentmacri vincentmacri commented Oct 27, 2025

Replace things like List[T] with list[T] in type annotations. Enables this rule in CI and in configuration files.

To do this I used ruff to fix UP006, then fixed F401 on the changed files (to remove the UP006 unused imports left behind by UP006).

There are several other ruff UP rules that have autofix and can easily be enabled. To keep the PR a reasonable size we only do UP006 here.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

@vincentmacri vincentmacri added t: refactoring github_actions Pull requests that update GitHub Actions code labels Oct 27, 2025
# 2 PLE0302 [ ] The special method `__len__` expects 1 parameter, 3 were given
# 1 F402 [ ] Import `factor` from line 259 shadowed by loop variable
# 1 PLC0208 [*] Use a sequence type instead of a `set` when iterating over values
# 10589 PLC0415 [ ] import-outside-top-level
Copy link
Member Author

Choose a reason for hiding this comment

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

I updated this comment while I was touching this file. Looks like that hasn't been done in a while.

[tool.ruff.lint]
ignore = [
"E501", # Line too long - hard to avoid in doctests, and better handled by black.
"UP045", # non-pep604-annotation-optional - Whether `Optional[T]` or `T | None` is better is subjective.
Copy link
Member Author

Choose a reason for hiding this comment

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

In preparation for eventually being able to enable more/all UP rules. At first glance this was the only one I saw that seemed potentially controversial. I'm not taking a stance on it for this PR, but my personal opinion is that Optional is more readable for parameters and less readable for return values.

Other rules in UP that would have a big impact for us: changing old-style string formatting to f-strings. I think that's only an issue for us because of how many files it would change. In principle I think f-strings are far more readable, but unless we want to do a patch bomb it's hard to see us ever transitioning the entire code base to f-strings. (I guess in theory we could do some kind of git hook autoformat when files get changed for other reasons to slowly transition things over automatically, but I think that would be controversial.)

@github-actions
Copy link

github-actions bot commented Oct 27, 2025

Documentation preview for this PR (built with commit 787b086; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

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

Labels

github_actions Pull requests that update GitHub Actions code s: needs review t: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant