Skip to content

Turn on ruff's pyupgrade rules - #2976

Merged
pvcraven merged 1 commit into
developmentfrom
pyupgrade-collections-abc
Oct 9, 2026
Merged

pvcraven merged 1 commit into
developmentfrom
pyupgrade-collections-abc

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 9, 2026

Copy link
Copy Markdown
Member

Closes #2676

#2677 turned on ruff's pyupgrade (UP) rules, then turned them off again: # "UP", wait for arcade.gl abstraction merge. That merge (#2666) and the pyglet 3 migration have both landed, so this turns the rules on for arcade and tests and applies the fixes.

What changed (43 files, +195/−217)

Almost all of it is ruff's own autofix, mostly in arcade/gl:

Rule Count Change
UP006 65 List[int], Dict, Tuple, Type → list[int] and other builtins
UP035 42 Iterable, Sequence, Callable and similar imported from collections.abc instead of typing (the issue's request)
UP034 16 extra parentheses removed
UP037 15 quotes removed from annotations, only in files with from __future__ import annotations
UP032 13 .format() → f-strings
UP007/UP045 6 Union[X, Y] / Optional[X] → X | Y / X | None

By hand:

  • arcade/gl/types.py: BufferOrBufferProtocol = Union[BufferProtocol, Buffer] → BufferProtocol | Buffer. Ruff doesn't rewrite a Union assigned to a name. It's safe at runtime on Python 3.10+, whichever form BufferProtocol has.
  • tests/unit/gui/__init__.py: removed an unused from typing import List. Ruff won't remove imports from an __init__.py automatically.
  • Four __repr__ methods in the OpenGL and WebGL texture.py / texture_array.py: UP032 made their f-strings longer than 100 characters, so they're split across two lines.

Nothing changes at runtime. These are annotations, imports and string formatting. The examples are outside ruff's scope and unchanged. The changelog entry is under Misc Changes.

Checked

  • ruff (lint, import order, format), mypy and pyright pass.
  • The full test suite (1851) passes.
  • make.py docs-full (nitpicky Sphinx build plus the internal link check) passes. The arcade.gl signatures now name collections.abc types, which link to Python's docs.

🤖 Generated with Claude Code

The rules were turned off in #2677 until the arcade.gl abstraction and
the pyglet 3 migration merged, to avoid conflicts. Both have merged.
Most changes are ruff's own fixes in arcade.gl: typing.List/Dict/Tuple
become builtins, Iterable/Sequence/Callable come from collections.abc,
Union/Optional become X | Y, and .format() becomes f-strings. By hand:
a Union type alias in arcade.gl.types, an unused import ruff won't
remove from an __init__.py, and four __repr__ lines ruff made too long.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvcraven
pvcraven merged commit d7c3474 into development Oct 9, 2026
7 checks passed
@pvcraven
pvcraven deleted the pyupgrade-collections-abc branch October 9, 2026 20:47
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.

Typing: Use collections.abc instead of typing module

1 participant