Skip to content

Commit feb6dd0

Browse files
committed
Use list/tuple instead of typing.Tuple etc
1 parent 498a57f commit feb6dd0

28 files changed

+230
-250
lines changed

pymunk/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
This is the main containing module of Pymunk. It contains among other things
3131
the very central Space, Body and Shape classes.
3232
33-
Pymunk uses the standard logging module to log helpful information. It does
33+
Pymunk uses the standard logging module to log helpful information. It does
3434
that under the "pymunk" name. If you do not do anything setup, it will print
35-
WARNING and higher messages to stderr. (Note that you most likely do not want
36-
to set logLevel to DEBUG, since Pymunk might log a lot of debug level
35+
WARNING and higher messages to stderr. (Note that you most likely do not want
36+
to set logLevel to DEBUG, since Pymunk might log a lot of debug level
3737
messages mostly useful during development of Pymunk itself.)
3838
3939
"""
@@ -68,7 +68,7 @@
6868
"Vec2d",
6969
]
7070

71-
from typing import Sequence, Tuple, cast
71+
from typing import Sequence, cast
7272

7373
from . import _chipmunk_cffi
7474

@@ -119,7 +119,7 @@ def moment_for_circle(
119119
mass: float,
120120
inner_radius: float,
121121
outer_radius: float,
122-
offset: Tuple[float, float] = (0, 0),
122+
offset: tuple[float, float] = (0, 0),
123123
) -> float:
124124
"""Calculate the moment of inertia for a hollow circle
125125
@@ -131,7 +131,7 @@ def moment_for_circle(
131131

132132

133133
def moment_for_segment(
134-
mass: float, a: Tuple[float, float], b: Tuple[float, float], radius: float
134+
mass: float, a: tuple[float, float], b: tuple[float, float], radius: float
135135
) -> float:
136136
"""Calculate the moment of inertia for a line segment
137137
@@ -143,7 +143,7 @@ def moment_for_segment(
143143
return cp.cpMomentForSegment(mass, a, b, radius)
144144

145145

146-
def moment_for_box(mass: float, size: Tuple[float, float]) -> float:
146+
def moment_for_box(mass: float, size: tuple[float, float]) -> float:
147147
"""Calculate the moment of inertia for a solid box centered on the body.
148148
149149
size should be a tuple of (width, height)
@@ -154,8 +154,8 @@ def moment_for_box(mass: float, size: Tuple[float, float]) -> float:
154154

155155
def moment_for_poly(
156156
mass: float,
157-
vertices: Sequence[Tuple[float, float]],
158-
offset: Tuple[float, float] = (0, 0),
157+
vertices: Sequence[tuple[float, float]],
158+
offset: tuple[float, float] = (0, 0),
159159
radius: float = 0,
160160
) -> float:
161161
"""Calculate the moment of inertia for a solid polygon shape.
@@ -174,7 +174,7 @@ def area_for_circle(inner_radius: float, outer_radius: float) -> float:
174174

175175

176176
def area_for_segment(
177-
a: Tuple[float, float], b: Tuple[float, float], radius: float
177+
a: tuple[float, float], b: tuple[float, float], radius: float
178178
) -> float:
179179
"""Area of a beveled segment.
180180
@@ -186,7 +186,7 @@ def area_for_segment(
186186
return cp.cpAreaForSegment(a, b, radius)
187187

188188

189-
def area_for_poly(vertices: Sequence[Tuple[float, float]], radius: float = 0) -> float:
189+
def area_for_poly(vertices: Sequence[tuple[float, float]], radius: float = 0) -> float:
190190
"""Signed area of a polygon shape.
191191
192192
Returns a negative number for polygons with a clockwise winding.

pymunk/_pickle.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import copy
2-
from typing import Any, ClassVar, Dict, List, Tuple, TypeVar
2+
from typing import Any, ClassVar, TypeVar
33

44
T = TypeVar("T", bound="PickleMixin")
5-
_State = Dict[str, List[Tuple[str, Any]]]
5+
_State = dict[str, list[tuple[str, Any]]]
66

77

88
class PickleMixin:
99
"""PickleMixin is used to provide base functionality for pickle/unpickle
1010
and copy.
1111
"""
1212

13-
_pickle_attrs_init: ClassVar[List[str]] = []
14-
_pickle_attrs_general: ClassVar[List[str]] = []
15-
_pickle_attrs_skip: ClassVar[List[str]] = []
13+
_pickle_attrs_init: ClassVar[list[str]] = []
14+
_pickle_attrs_general: ClassVar[list[str]] = []
15+
_pickle_attrs_skip: ClassVar[list[str]] = []
1616

1717
def __getstate__(self) -> _State:
1818
"""Return the state of this object
@@ -46,7 +46,7 @@ def __setstate__(self, state: _State) -> None:
4646
modules with this class.
4747
"""
4848

49-
init_attrs: List[str] = []
49+
init_attrs: list[str] = []
5050

5151
init_args = [v for k, v in state["init"]]
5252
self.__init__(*init_args) # type: ignore

pymunk/_pyglet15_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
# SOFTWARE.
2222
# ----------------------------------------------------------------------------
2323

24-
"""This submodule contains helper functions to help with quick prototyping
24+
"""This submodule contains helper functions to help with quick prototyping
2525
using pymunk together with pyglet.
2626
2727
Intended to help with debugging and prototyping, not for actual production use
28-
in a full application. The methods contained in this module is opinionated
29-
about your coordinate system and not very optimized (they use batched
30-
drawing, but there is probably room for optimizations still).
28+
in a full application. The methods contained in this module is opinionated
29+
about your coordinate system and not very optimized (they use batched
30+
drawing, but there is probably room for optimizations still).
3131
"""
3232

3333
__docformat__ = "reStructuredText"
3434

3535
import math
3636
import warnings
37-
from typing import TYPE_CHECKING, Any, List, Optional, Sequence, Type
37+
from typing import TYPE_CHECKING, Any, Optional, Sequence, Type
3838

3939
import pyglet # type: ignore
4040

@@ -92,7 +92,7 @@ def __init__(self, **kwargs: Any) -> None:
9292
9393
"""
9494
self.new_batch = False
95-
self.draw_shapes: List[Any] = []
95+
self.draw_shapes: list[Any] = []
9696

9797
if "batch" not in kwargs:
9898
self.new_batch = True

pymunk/_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import TYPE_CHECKING, List, Tuple, Union
1+
from typing import TYPE_CHECKING, Union
22

33
if TYPE_CHECKING:
44
from .vec2d import Vec2d
55

6-
_Vec2dOrTuple = Union[Tuple[float, float], List[float], "Vec2d"]
7-
_Vec2dOrFloat = Union[Tuple[float, float], List[float], "Vec2d", float]
6+
_Vec2dOrTuple = Union[tuple[float, float], list[float], "Vec2d"]
7+
_Vec2dOrFloat = Union[tuple[float, float], list[float], "Vec2d", float]

pymunk/arbiter.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__docformat__ = "reStructuredText"
22

33

4-
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Tuple
4+
from typing import TYPE_CHECKING, Any, Sequence
55

66
if TYPE_CHECKING:
77
from .space import Space
@@ -91,7 +91,7 @@ def contact_point_set(self, point_set: ContactPointSet) -> None:
9191
lib.cpArbiterSetContactPointSet(self._arbiter, ffi.addressof(_set))
9292

9393
@property
94-
def bodies(self) -> Tuple["Body", "Body"]:
94+
def bodies(self) -> tuple["Body", "Body"]:
9595
"""The the bodies in the order their corresponding shapes were defined
9696
in the collision handler associated with this arbiter.
9797
@@ -109,7 +109,7 @@ def bodies(self) -> Tuple["Body", "Body"]:
109109
return a.body, b.body
110110

111111
@property
112-
def shapes(self) -> Tuple["Shape", "Shape"]:
112+
def shapes(self) -> tuple["Shape", "Shape"]:
113113
"""Get the shapes in the order that they were defined in the
114114
collision handler associated with this arbiter
115115
"""
@@ -156,7 +156,7 @@ def _get_surface_velocity(self) -> Vec2d:
156156
v = lib.cpArbiterGetSurfaceVelocity(self._arbiter)
157157
return Vec2d(v.x, v.y)
158158

159-
def _set_surface_velocity(self, velocity: Tuple[float, float]) -> None:
159+
def _set_surface_velocity(self, velocity: tuple[float, float]) -> None:
160160
lib.cpArbiterSetSurfaceVelocity(self._arbiter, velocity)
161161

162162
surface_velocity = property(
@@ -223,14 +223,14 @@ def normal(self) -> Vec2d:
223223

224224
def _contacts_to_dicts(
225225
_contacts: Sequence[ffi.CData], count: int
226-
) -> List[Dict[str, Any]]:
226+
) -> list[dict[str, Any]]:
227227
res = []
228228
for i in range(count):
229229
res.append(_contact_to_dict(_contacts[i]))
230230
return res
231231

232232

233-
def _contact_to_dict(_contact: ffi.CData) -> Dict[str, Any]:
233+
def _contact_to_dict(_contact: ffi.CData) -> dict[str, Any]:
234234
d = {}
235235
d["r1"] = _contact.r1.x, _contact.r1.y
236236
d["r2"] = _contact.r2.x, _contact.r2.y
@@ -245,7 +245,7 @@ def _contact_to_dict(_contact: ffi.CData) -> Dict[str, Any]:
245245
return d
246246

247247

248-
def _contacts_from_dicts(ds: Sequence[Dict[str, Any]]) -> List[ffi.CData]:
248+
def _contacts_from_dicts(ds: Sequence[dict[str, Any]]) -> dist[ffi.CData]:
249249
_contacts = lib.cpContactArrAlloc(len(ds))
250250
for i in range(len(ds)):
251251
_contact = _contacts[i]
@@ -265,7 +265,7 @@ def _contacts_from_dicts(ds: Sequence[Dict[str, Any]]) -> List[ffi.CData]:
265265
return _contacts
266266

267267

268-
def _arbiter_from_dict(d: Dict[str, Any], space: "Space") -> ffi.CData:
268+
def _arbiter_from_dict(d: dict[str, Any], space: "Space") -> ffi.CData:
269269
_arb = lib.cpArbiterNew(
270270
d["a"]._shape, d["b"]._shape
271271
) # this will also set the bodies
@@ -285,7 +285,7 @@ def _arbiter_from_dict(d: Dict[str, Any], space: "Space") -> ffi.CData:
285285
return _arb
286286

287287

288-
def _arbiter_to_dict(_arbiter: ffi.CData, space: "Space") -> Dict[str, Any]:
288+
def _arbiter_to_dict(_arbiter: ffi.CData, space: "Space") -> dict[str, Any]:
289289
d = {}
290290
d["e"] = _arbiter.e
291291
d["u"] = _arbiter.u

pymunk/autogeometry.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
__docformat__ = "reStructuredText"
4141

42-
from typing import TYPE_CHECKING, Callable, List, Sequence, Tuple, Union, overload
42+
from typing import TYPE_CHECKING, Callable, Sequence, Union, overload
4343

4444
if TYPE_CHECKING:
4545
from .bb import BB
@@ -48,11 +48,11 @@
4848
from ._chipmunk_cffi import ffi, lib
4949
from .vec2d import Vec2d
5050

51-
_SampleFunc = Callable[[Tuple[float, float]], float]
51+
_SampleFunc = Callable[[tuple[float, float]], float]
5252

53-
_Polyline = Union[List[Tuple[float, float]], List[Vec2d]]
53+
_Polyline = Union[list[tuple[float, float]], list[Vec2d]]
5454
# Union is needed since List is invariant
55-
# and Sequence cant be used since CFFI requires a List (or Tuple)
55+
# and Sequence cant be used since CFFI requires a list (or tuple)
5656

5757

5858
def _to_chipmunk(polyline: _Polyline) -> ffi.CData:
@@ -64,7 +64,7 @@ def _to_chipmunk(polyline: _Polyline) -> ffi.CData:
6464
return _line
6565

6666

67-
def _from_polyline_set(_set: ffi.CData) -> List[List[Vec2d]]:
67+
def _from_polyline_set(_set: ffi.CData) -> list[list[Vec2d]]:
6868
lines = []
6969
for i in range(_set.count):
7070
line = []
@@ -85,7 +85,7 @@ def is_closed(polyline: _Polyline) -> bool:
8585
return bool(lib.cpPolylineIsClosed(_to_chipmunk(polyline)))
8686

8787

88-
def simplify_curves(polyline: _Polyline, tolerance: float) -> List[Vec2d]:
88+
def simplify_curves(polyline: _Polyline, tolerance: float) -> list[Vec2d]:
8989
"""Returns a copy of a polyline simplified by using the Douglas-Peucker
9090
algorithm.
9191
@@ -105,7 +105,7 @@ def simplify_curves(polyline: _Polyline, tolerance: float) -> List[Vec2d]:
105105
return simplified
106106

107107

108-
def simplify_vertexes(polyline: _Polyline, tolerance: float) -> List[Vec2d]:
108+
def simplify_vertexes(polyline: _Polyline, tolerance: float) -> list[Vec2d]:
109109
"""Returns a copy of a polyline simplified by discarding "flat" vertexes.
110110
111111
This works well on straight edged or angular shapes, not as well on smooth
@@ -123,7 +123,7 @@ def simplify_vertexes(polyline: _Polyline, tolerance: float) -> List[Vec2d]:
123123
return simplified
124124

125125

126-
def to_convex_hull(polyline: _Polyline, tolerance: float) -> List[Vec2d]:
126+
def to_convex_hull(polyline: _Polyline, tolerance: float) -> list[Vec2d]:
127127
"""Get the convex hull of a polyline as a looped polyline.
128128
129129
:param polyline: Polyline to simplify.
@@ -138,7 +138,7 @@ def to_convex_hull(polyline: _Polyline, tolerance: float) -> List[Vec2d]:
138138
return hull
139139

140140

141-
def convex_decomposition(polyline: _Polyline, tolerance: float) -> List[List[Vec2d]]:
141+
def convex_decomposition(polyline: _Polyline, tolerance: float) -> list[list[Vec2d]]:
142142
"""Get an approximate convex decomposition from a polyline.
143143
144144
Returns a list of convex hulls that match the original shape to within
@@ -164,7 +164,7 @@ def convex_decomposition(polyline: _Polyline, tolerance: float) -> List[List[Vec
164164
return _from_polyline_set(_set)
165165

166166

167-
class PolylineSet(Sequence[List[Vec2d]]):
167+
class PolylineSet(Sequence[list[Vec2d]]):
168168
"""A set of Polylines.
169169
170170
Mainly intended to be used for its :py:meth:`collect_segment` function
@@ -180,7 +180,7 @@ def free(_set: ffi.CData) -> None:
180180

181181
self._set = ffi.gc(lib.cpPolylineSetNew(), free)
182182

183-
def collect_segment(self, v0: Tuple[float, float], v1: Tuple[float, float]) -> None:
183+
def collect_segment(self, v0: tuple[float, float], v1: tuple[float, float]) -> None:
184184
"""Add a line segment to a polyline set.
185185
186186
A segment will either start a new polyline, join two others, or add to
@@ -201,14 +201,14 @@ def __len__(self) -> int:
201201
return self._set.count
202202

203203
@overload
204-
def __getitem__(self, index: int) -> List[Vec2d]: ...
204+
def __getitem__(self, index: int) -> list[Vec2d]: ...
205205

206206
@overload
207207
def __getitem__(self, index: slice) -> "PolylineSet": ...
208208

209209
def __getitem__(
210210
self, index: Union[int, slice]
211-
) -> Union[List[Vec2d], "PolylineSet"]:
211+
) -> Union[list[Vec2d], "PolylineSet"]:
212212
assert not isinstance(index, slice), "Slice indexing not supported"
213213
if index >= self._set.count:
214214
raise IndexError
@@ -238,7 +238,7 @@ def march_soft(
238238
:param sample_func: The sample function will be called for
239239
x_samples * y_samples spread across the bounding box area, and should
240240
return a float.
241-
:type sample_func: ``func(point: Tuple[float, float]) -> float``
241+
:type sample_func: ``func(point: tuple[float, float]) -> float``
242242
:return: PolylineSet with the polylines found.
243243
"""
244244
pl_set = PolylineSet()
@@ -278,7 +278,7 @@ def march_hard(
278278
:param sample_func: The sample function will be called for
279279
x_samples * y_samples spread across the bounding box area, and should
280280
return a float.
281-
:type sample_func: ``func(point: Tuple[float, float]) -> float``
281+
:type sample_func: ``func(point: tuple[float, float]) -> float``
282282
:return: PolylineSet with the polylines found.
283283
"""
284284

0 commit comments

Comments
 (0)