Skip to content

Commit b3c30bf

Browse files
authored
Upgrade to pyton 3.10 (#2677)
* enable pyupgrade for ruff, migrate to 3.10 featured typing * fix arcade python version warning (req 3.10 * fix formating * revert arcade.gl changes to reduce merge issues for gl abstraction PR
1 parent 441287b commit b3c30bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+284
-298
lines changed

arcade/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
from pathlib import Path
1414

15-
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 9):
16-
sys.exit("The Arcade Library requires Python 3.9 or higher.")
15+
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 10):
16+
sys.exit("The Arcade Library requires Python 3.10 or higher.")
1717

1818

1919
def configure_logging(level: int | None = None):

arcade/application.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import logging
99
import os
1010
import time
11-
from typing import TYPE_CHECKING, Sequence
11+
from collections.abc import Sequence
12+
from typing import TYPE_CHECKING
1213

1314
import pyglet
1415
import pyglet.gl as gl
@@ -36,7 +37,7 @@
3637
MOUSE_BUTTON_MIDDLE = 2
3738
MOUSE_BUTTON_RIGHT = 4
3839

39-
_window: "Window"
40+
_window: Window
4041

4142
__all__ = [
4243
"get_screens",

arcade/cache/hit_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def load(self, path: str | Path) -> None:
118118
with gzip.open(path, mode="rb") as fd:
119119
data = json.loads(fd.read())
120120
else:
121-
with open(path, mode="r") as fd:
121+
with open(path) as fd:
122122
data = json.loads(fd.read())
123123

124124
for key, value in data.items():

arcade/cache/image_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class ImageDataCache:
2323
"""
2424

2525
def __init__(self):
26-
self._entries: dict[str, "ImageData"] = {}
26+
self._entries: dict[str, ImageData] = {}
2727

28-
def put(self, name: str, image: "ImageData"):
28+
def put(self, name: str, image: ImageData):
2929
"""
3030
Add an image to the cache.
3131

arcade/camera/camera_2d.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3+
from collections.abc import Generator
34
from contextlib import contextmanager
45
from math import atan2, cos, degrees, radians, sin
5-
from typing import TYPE_CHECKING, Generator
6+
from typing import TYPE_CHECKING
67

78
from pyglet.math import Vec2, Vec3
89
from typing_extensions import Self
@@ -223,12 +224,12 @@ def from_camera_data(
223224
left, right = projection_data.left, projection_data.right
224225
if projection_data.left == projection_data.right:
225226
raise ZeroProjectionDimension(
226-
(f"projection width is 0 due to equal {left=}and {right=} values")
227+
f"projection width is 0 due to equal {left=}and {right=} values"
227228
)
228229
bottom, top = projection_data.bottom, projection_data.top
229230
if bottom == top:
230231
raise ZeroProjectionDimension(
231-
(f"projection height is 0 due to equal {bottom=}and {top=}")
232+
f"projection height is 0 due to equal {bottom=}and {top=}"
232233
)
233234
near, far = projection_data.near, projection_data.far
234235
if near == far:
@@ -583,7 +584,7 @@ def projection(self) -> Rect:
583584
def projection(self, value: Rect) -> None:
584585
# Unpack and validate
585586
if not value:
586-
raise ZeroProjectionDimension((f"Projection area is 0, {value.lrbt}"))
587+
raise ZeroProjectionDimension(f"Projection area is 0, {value.lrbt}")
587588

588589
_z = self._camera_data.zoom
589590

arcade/camera/data_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
wide usage throughout Arcade's camera code.
55
"""
66

7+
from collections.abc import Generator
78
from contextlib import contextmanager
8-
from typing import Final, Generator, Protocol
9+
from typing import Final, Protocol
910

1011
from pyglet.math import Vec2, Vec3
1112
from typing_extensions import Self

arcade/camera/default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3+
from collections.abc import Generator
34
from contextlib import contextmanager
4-
from typing import TYPE_CHECKING, Generator
5+
from typing import TYPE_CHECKING
56

67
from pyglet.math import Mat4, Vec2, Vec3
78
from typing_extensions import Self

arcade/camera/orthographic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3+
from collections.abc import Generator
34
from contextlib import contextmanager
4-
from typing import TYPE_CHECKING, Generator
5+
from typing import TYPE_CHECKING
56

67
from pyglet.math import Mat4, Vec2, Vec3
78
from typing_extensions import Self

arcade/camera/perspective.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3+
from collections.abc import Generator
34
from contextlib import contextmanager
45
from math import radians, tan
5-
from typing import TYPE_CHECKING, Generator
6+
from typing import TYPE_CHECKING
67

78
from pyglet.math import Mat4, Vec2, Vec3
89
from typing_extensions import Self

arcade/camera/static.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3+
from collections.abc import Callable, Generator
34
from contextlib import contextmanager
4-
from typing import TYPE_CHECKING, Callable, Generator
5+
from typing import TYPE_CHECKING
56

67
from pyglet.math import Mat4, Vec2, Vec3
78

arcade/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Contains pre-loaded programs
44
"""
55

6+
from collections.abc import Iterable, Sequence
67
from pathlib import Path
7-
from typing import Any, Iterable, Sequence
8+
from typing import Any
89

910
import pyglet
1011
from PIL import Image

arcade/easing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Functions used to support easing
33
"""
44

5+
from collections.abc import Callable
56
from dataclasses import dataclass
67
from math import cos, pi, sin
7-
from typing import Callable
88

99
from .math import get_distance
1010

arcade/examples/dual_stick_shooter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
def dump_obj(obj):
3232
for key in sorted(vars(obj)):
3333
val = getattr(obj, key)
34-
print("{:30} = {} ({})".format(key, val, type(val).__name__))
34+
print(f"{key:30} = {val} ({type(val).__name__})")
3535

3636

3737
def dump_controller(controller):
38-
print("========== {}".format(controller))
39-
print("Left X {}".format(controller.leftx))
40-
print("Left Y {}".format(controller.lefty))
41-
print("Left Trigger {}".format(controller.lefttrigger))
42-
print("Right X {}".format(controller.rightx))
43-
print("Right Y {}".format(controller.righty))
44-
print("Right Trigger {}".format(controller.righttrigger))
38+
print(f"========== {controller}")
39+
print(f"Left X {controller.leftx}")
40+
print(f"Left Y {controller.lefty}")
41+
print(f"Left Trigger {controller.lefttrigger}")
42+
print(f"Right X {controller.rightx}")
43+
print(f"Right Y {controller.righty}")
44+
print(f"Right Trigger {controller.righttrigger}")
4545
print("========== Extra controller")
4646
dump_obj(controller)
4747
print("========== Extra controller.device")

arcade/examples/gl/3d_cube_with_cubes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ def __init__(self, width, height, title):
9797
self.frame = 0
9898

9999
self.fbo1 = self.ctx.framebuffer(
100-
color_attachments=[self.ctx.texture((self.get_size()))],
100+
color_attachments=[self.ctx.texture(self.get_size())],
101101
depth_attachment=self.ctx.depth_texture(self.get_size()),
102102
)
103103
self.fbo2 = self.ctx.framebuffer(
104-
color_attachments=[self.ctx.texture((self.get_size()))],
104+
color_attachments=[self.ctx.texture(self.get_size())],
105105
depth_attachment=self.ctx.depth_texture(self.get_size()),
106106
)
107107

arcade/examples/gl/bindless_texture.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"""
2727

2828
from array import array
29-
from typing import List
3029
from itertools import cycle
3130

3231
import arcade
@@ -144,7 +143,7 @@ def __init__(self):
144143
)
145144

146145
self.handles = []
147-
self.textures: List[Texture2D] = []
146+
self.textures: list[Texture2D] = []
148147
# Make a cycle iterator from Arcade's resources (images)
149148
resources = arcade.resources.list_built_in_assets(name="female", extensions=(".png",))
150149
resource_cycle = cycle(resources)

arcade/examples/gl/render_indirect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ def on_draw(self):
238238
# to prove that partial rendering also works.
239239
# NOTE: These values can be skewed if vsync is enabled
240240
print(
241-
(
241+
242242
f"[{method}] "
243243
f"Pixels written = {self.query.samples_passed // 4}, "
244244
f"Primitives Generated = {self.query.primitives_generated}, "
245245
f"time = {self.query.time_elapsed / 1_000_000_000}s"
246-
)
246+
247247
)
248248

249249
def on_update(self, delta_time: float):

arcade/examples/gl/spritelist_interaction_visualize_dist_los_trans.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ def on_draw(self):
202202
)
203203
print("Indices found:", sprite_indices)
204204
print(
205-
(
205+
206206
f"max(sprite_indices) = {max(sprite_indices)} | "
207207
f"len(self.coins) = {len(self.coins)} | "
208208
f"sprite_indices = {len(sprite_indices)}"
209-
)
209+
210210
)
211211
# Resolve the list of selected sprites and remove them
212212
sprites = [self.coins[int(i)] for i in sprite_indices]

arcade/examples/gui/exp_controller_inventory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""
1616

1717
# TODO: Drag and Drop
18-
from typing import List, Optional
1918

2019
import pyglet.font
2120
from pyglet.event import EVENT_HANDLED
@@ -75,7 +74,7 @@ class Inventory:
7574
"""
7675

7776
def __init__(self, capacity: int):
78-
self._items: List[Item | None] = [None for _ in range(capacity)]
77+
self._items: list[Item | None] = [None for _ in range(capacity)]
7978
self.capacity = capacity
8079

8180
def add(self, item: Item):
@@ -352,7 +351,7 @@ def __init__(self, inventory: Inventory, **kwargs):
352351
# init controller support
353352
self.detect_focusable_widgets()
354353

355-
def on_event(self, event: UIEvent) -> Optional[bool]:
354+
def on_event(self, event: UIEvent) -> bool | None:
356355
if isinstance(event, UIControllerButtonPressEvent):
357356
if event.button == "b":
358357
self.set_focus(self.close_button)

arcade/examples/gui/exp_controller_support.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
python -m arcade.examples.gui.exp_controller_support
1010
"""
1111

12-
from typing import Optional
1312

1413
import arcade
1514
from arcade import Texture
@@ -115,7 +114,7 @@ def input_prompts(cls, event: UIControllerEvent) -> Texture | None:
115114

116115
return None
117116

118-
def on_event(self, event: UIEvent) -> Optional[bool]:
117+
def on_event(self, event: UIEvent) -> bool | None:
119118
if isinstance(event, UIControllerEvent):
120119
input_texture = self.input_prompts(event)
121120

arcade/examples/gui/exp_controller_support_grid.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
python -m arcade.examples.gui.exp_controller_support_grid
1010
"""
1111

12-
from typing import Dict, Tuple
1312

1413
import arcade
1514
from arcade.examples.gui.exp_controller_support import ControllerIndicator
@@ -27,7 +26,7 @@ class FocusableButton(UIFocusable, UIFlatButton):
2726
pass
2827

2928

30-
def setup_grid_focus_transition(grid: Dict[Tuple[int, int], UIWidget]):
29+
def setup_grid_focus_transition(grid: dict[tuple[int, int], UIWidget]):
3130
"""Setup focus transition in grid.
3231
3332
Connect focus transition between `Focusable` in grid.

arcade/examples/particle_systems.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ def __init__(self):
808808

809809
def next_emitter(self, _time_delta):
810810
self.emitter_factory_id = (self.emitter_factory_id + 1) % len(self.factories)
811-
print("Changing emitter to {}".format(self.emitter_factory_id))
811+
print(f"Changing emitter to {self.emitter_factory_id}")
812812
self.emitter_timeout = 0
813813
self.label, self.emitter = self.factories[self.emitter_factory_id]()
814814

@@ -827,7 +827,7 @@ def on_draw(self):
827827
self.clear()
828828
arcade.draw_sprite(self.obj)
829829
if self.label:
830-
arcade.draw_text("#{} {}".format(self.emitter_factory_id, self.label),
830+
arcade.draw_text(f"#{self.emitter_factory_id} {self.label}",
831831
WINDOW_WIDTH / 2, WINDOW_HEIGHT - 25,
832832
arcade.color.PALE_GOLD, 20, width=WINDOW_WIDTH,
833833
anchor_x="center")

arcade/examples/sprite_health.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
python -m arcade.examples.sprite_health
88
"""
99
import math
10-
from typing import Tuple
1110

1211
import arcade
1312
from arcade.types import Color
@@ -102,13 +101,13 @@ def __init__(
102101
self,
103102
owner: Player,
104103
sprite_list: arcade.SpriteList,
105-
position: Tuple[float, float] = (0, 0),
104+
position: tuple[float, float] = (0, 0),
106105
full_color: Color = arcade.color.GREEN,
107106
background_color: Color = arcade.color.BLACK,
108107
width: int = 100,
109108
height: int = 4,
110109
border_size: int = 4,
111-
scale: Tuple[float, float] = (1.0, 1.0),
110+
scale: tuple[float, float] = (1.0, 1.0),
112111
) -> None:
113112
# Store the reference to the owner and the sprite list
114113
self.owner: Player = owner
@@ -120,7 +119,7 @@ def __init__(
120119
self._center_x: float = 0.0
121120
self._center_y: float = 0.0
122121
self._fullness: float = 0.0
123-
self._scale: Tuple[float, float] = (1.0, 1.0)
122+
self._scale: tuple[float, float] = (1.0, 1.0)
124123

125124
# Create the boxes needed to represent the indicator bar
126125
self._background_box: arcade.SpriteSolidColor = arcade.SpriteSolidColor(
@@ -220,12 +219,12 @@ def fullness(self, new_fullness: float) -> None:
220219
self.full_box.left = self._center_x - (self._bar_width / 2) * self.scale[0]
221220

222221
@property
223-
def position(self) -> Tuple[float, float]:
222+
def position(self) -> tuple[float, float]:
224223
"""Returns the current position of the bar."""
225224
return self._center_x, self._center_y
226225

227226
@position.setter
228-
def position(self, new_position: Tuple[float, float]) -> None:
227+
def position(self, new_position: tuple[float, float]) -> None:
229228
"""Sets the new position of the bar."""
230229
# Check if the position has changed. If so, change the bar's position
231230
if new_position != self.position:
@@ -237,12 +236,12 @@ def position(self, new_position: Tuple[float, float]) -> None:
237236
self.full_box.left = self._center_x - (self._bar_width / 2) * self.scale[0]
238237

239238
@property
240-
def scale(self) -> Tuple[float, float]:
239+
def scale(self) -> tuple[float, float]:
241240
"""Returns the scale of the bar."""
242241
return self._scale
243242

244243
@scale.setter
245-
def scale(self, value: Tuple[float, float]) -> None:
244+
def scale(self, value: tuple[float, float]) -> None:
246245
"""Sets the new scale of the bar."""
247246
# Check if the scale has changed. If so, change the bar's scale
248247
if value != self.scale:

0 commit comments

Comments
 (0)