Skip to content

Commit 789d83c

Browse files
committed
improved types
1 parent 6c6e966 commit 789d83c

File tree

8 files changed

+65
-24
lines changed

8 files changed

+65
-24
lines changed

pymunk/_callbacks.py

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414

1515

1616
@ffi.def_extern()
17-
def ext_cpSpacePointQueryFunc(_shape, point, distance, gradient, data): # type: ignore
17+
def ext_cpSpacePointQueryFunc(
18+
_shape: ffi.CData,
19+
point: ffi.CData,
20+
distance: float,
21+
gradient: ffi.CData,
22+
data: ffi.CData,
23+
) -> None:
1824
self, query_hits = ffi.from_handle(data)
1925
shape = self._get_shape(_shape)
2026
p = PointQueryInfo(
@@ -24,7 +30,13 @@ def ext_cpSpacePointQueryFunc(_shape, point, distance, gradient, data): # type:
2430

2531

2632
@ffi.def_extern()
27-
def ext_cpSpaceSegmentQueryFunc(_shape, point, normal, alpha, data): # type: ignore
33+
def ext_cpSpaceSegmentQueryFunc(
34+
_shape: ffi.CData,
35+
point: ffi.CData,
36+
normal: ffi.CData,
37+
alpha: float,
38+
data: ffi.CData,
39+
) -> None:
2840
self, query_hits = ffi.from_handle(data)
2941
shape = self._get_shape(_shape)
3042
p = SegmentQueryInfo(
@@ -34,15 +46,17 @@ def ext_cpSpaceSegmentQueryFunc(_shape, point, normal, alpha, data): # type: ig
3446

3547

3648
@ffi.def_extern()
37-
def ext_cpSpaceBBQueryFunc(_shape, data): # type: ignore
49+
def ext_cpSpaceBBQueryFunc(_shape: ffi.CData, data: ffi.CData) -> None:
3850
self, query_hits = ffi.from_handle(data)
3951
shape = self._get_shape(_shape)
4052
assert shape is not None
4153
query_hits.append(shape)
4254

4355

4456
@ffi.def_extern()
45-
def ext_cpSpaceShapeQueryFunc(_shape, _points, data): # type: ignore
57+
def ext_cpSpaceShapeQueryFunc(
58+
_shape: ffi.CData, _points: ffi.CData, data: ffi.CData
59+
) -> None:
4660
self, query_hits = ffi.from_handle(data)
4761
found_shape = self._get_shape(_shape)
4862
point_set = ContactPointSet._from_cp(_points)
@@ -54,19 +68,21 @@ def ext_cpSpaceShapeQueryFunc(_shape, _points, data): # type: ignore
5468

5569

5670
@ffi.def_extern()
57-
def ext_cpSpaceShapeIteratorFunc(cp_shape, data): # type: ignore
71+
def ext_cpSpaceShapeIteratorFunc(cp_shape: ffi.CData, data: ffi.CData) -> None:
5872
cp_shapes = ffi.from_handle(data)
5973
cp_shapes.append(cp_shape)
6074

6175

6276
@ffi.def_extern()
63-
def ext_cpSpaceConstraintIteratorFunc(cp_constraint, data): # type: ignore
77+
def ext_cpSpaceConstraintIteratorFunc(
78+
cp_constraint: ffi.CData, data: ffi.CData
79+
) -> None:
6480
cp_constraints = ffi.from_handle(data)
6581
cp_constraints.append(cp_constraint)
6682

6783

6884
@ffi.def_extern()
69-
def ext_cpSpaceBodyIteratorFunc(cp_body, data): # type:ignore
85+
def ext_cpSpaceBodyIteratorFunc(cp_body: ffi.CData, data: ffi.CData) -> None:
7086
cp_bodys = ffi.from_handle(data)
7187
cp_bodys.append(cp_body)
7288

@@ -75,7 +91,14 @@ def ext_cpSpaceBodyIteratorFunc(cp_body, data): # type:ignore
7591

7692

7793
@ffi.def_extern()
78-
def ext_cpSpaceDebugDrawCircleImpl(pos, angle, radius, outline_color, fill_color, data): # type: ignore
94+
def ext_cpSpaceDebugDrawCircleImpl(
95+
pos: ffi.CData,
96+
angle: float,
97+
radius: float,
98+
outline_color: ffi.CData,
99+
fill_color: ffi.CData,
100+
data: ffi.CData,
101+
) -> None:
79102
options, _ = ffi.from_handle(data)
80103
options.draw_circle(
81104
Vec2d(pos.x, pos.y),
@@ -87,7 +110,9 @@ def ext_cpSpaceDebugDrawCircleImpl(pos, angle, radius, outline_color, fill_color
87110

88111

89112
@ffi.def_extern()
90-
def ext_cpSpaceDebugDrawSegmentImpl(a, b, color, data): # type: ignore
113+
def ext_cpSpaceDebugDrawSegmentImpl(
114+
a: ffi.CData, b: ffi.CData, color: ffi.CData, data: ffi.CData
115+
) -> None:
91116
# sometimes a and/or b can be nan. For example if both endpoints
92117
# of a spring is at the same position. In those cases skip calling
93118
# the drawing method.
@@ -102,7 +127,14 @@ def ext_cpSpaceDebugDrawSegmentImpl(a, b, color, data): # type: ignore
102127

103128

104129
@ffi.def_extern()
105-
def ext_cpSpaceDebugDrawFatSegmentImpl(a, b, radius, outline_color, fill_color, data): # type: ignore
130+
def ext_cpSpaceDebugDrawFatSegmentImpl(
131+
a: ffi.CData,
132+
b: ffi.CData,
133+
radius: float,
134+
outline_color: ffi.CData,
135+
fill_color: ffi.CData,
136+
data: ffi.CData,
137+
) -> None:
106138
options, _ = ffi.from_handle(data)
107139
options.draw_fat_segment(
108140
Vec2d(a.x, a.y),
@@ -114,7 +146,14 @@ def ext_cpSpaceDebugDrawFatSegmentImpl(a, b, radius, outline_color, fill_color,
114146

115147

116148
@ffi.def_extern()
117-
def ext_cpSpaceDebugDrawPolygonImpl(count, verts, radius, outline_color, fill_color, data): # type: ignore
149+
def ext_cpSpaceDebugDrawPolygonImpl(
150+
count: int,
151+
verts: ffi.CData,
152+
radius: float,
153+
outline_color: ffi.CData,
154+
fill_color: ffi.CData,
155+
data: ffi.CData,
156+
) -> None:
118157
options, _ = ffi.from_handle(data)
119158
vs = []
120159
for i in range(count):
@@ -123,13 +162,15 @@ def ext_cpSpaceDebugDrawPolygonImpl(count, verts, radius, outline_color, fill_co
123162

124163

125164
@ffi.def_extern()
126-
def ext_cpSpaceDebugDrawDotImpl(size, pos, color, data): # type: ignore
165+
def ext_cpSpaceDebugDrawDotImpl(
166+
size: float, pos: ffi.CData, color: ffi.CData, data: ffi.CData
167+
) -> None:
127168
options, _ = ffi.from_handle(data)
128169
options.draw_dot(size, Vec2d(pos.x, pos.y), options._c(color))
129170

130171

131172
@ffi.def_extern()
132-
def ext_cpSpaceDebugDrawColorForShapeImpl(_shape, data): # type: ignore
173+
def ext_cpSpaceDebugDrawColorForShapeImpl(_shape: ffi.CData, data: ffi.CData) -> None:
133174
options, space = ffi.from_handle(data)
134175
shape = space._get_shape(_shape)
135176
return options.color_for_shape(shape)

pymunk/body.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def __init__(
198198
199199
"""
200200

201-
def freebody(cp_body): # type: ignore
201+
def freebody(cp_body: ffi.CData) -> None:
202202
_logger.debug("bodyfree start %s", cp_body)
203203

204204
# remove all shapes on this body from the space
@@ -641,7 +641,7 @@ def each_arbiter(
641641
self,
642642
func: Callable[..., None], # TODO: Fix me once PEP 612 is ready
643643
*args: Any,
644-
**kwargs: Any
644+
**kwargs: Any,
645645
) -> None:
646646
"""Run func on each of the arbiters on this body.
647647

pymunk/contact_point_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __repr__(self) -> str:
6565
return "ContactPointSet(normal={}, points={})".format(self.normal, self.points)
6666

6767
@classmethod
68-
def _from_cp(cls, _points: "ffi.CData") -> "ContactPointSet":
68+
def _from_cp(cls, _points: ffi.CData) -> "ContactPointSet":
6969
normal = Vec2d(_points.normal.x, _points.normal.y)
7070

7171
points = []

pymunk/shapes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _init(self, body: Optional["Body"], _shape: ffi.CData) -> None:
5858
if body is not None:
5959
body._shapes.add(self)
6060

61-
def shapefree(cp_shape): # type: ignore
61+
def shapefree(cp_shape: ffi.CData) -> None:
6262
_logger.debug("shapefree start %s", cp_shape)
6363
cp_space = cp.cpShapeGetSpace(cp_shape)
6464
if cp_space != ffi.NULL:

pymunk/space.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, threaded: bool = False) -> None:
9999
cp_space = cp.cpSpaceNew()
100100
freefunc = cp.cpSpaceFree
101101

102-
def spacefree(cp_space): # type: ignore
102+
def spacefree(cp_space: ffi.CData) -> None:
103103
_logger.debug("spacefree start %s", cp_space)
104104

105105
cp_shapes: List[Shape] = []
@@ -716,7 +716,7 @@ def add_post_step_callback(
716716
if key in self._post_step_callbacks:
717717
return False
718718

719-
def f(x): # type: ignore
719+
def f(x: "Space") -> None:
720720
callback_function(self, key, *args, **kwargs)
721721

722722
self._post_step_callbacks[key] = f

pymunk/tests/test_space.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def testRemoveInSeparateWithoutStep(self) -> None:
702702

703703
s.add(shape1, shape2, body2)
704704

705-
def separate(*_):
705+
def separate(*_: Any) -> None:
706706
pass
707707

708708
s.step(1)
@@ -732,11 +732,11 @@ def testCollisionHandlerRemoveAfterSeparate(self) -> None:
732732
space.add(shape1, body2, shape2, shape3, body3)
733733
print("START", shape1, shape2, shape3)
734734

735-
def separate(arbiter: p.Arbiter, space: p.Space, data):
735+
def separate(arbiter: p.Arbiter, space: p.Space, data: Any) -> None:
736736
print("SEP", arbiter.shapes)
737737
self.separate_occurred = True
738738

739-
def post_solve(arbiter: p.Arbiter, space: p.Space, data):
739+
def post_solve(arbiter: p.Arbiter, space: p.Space, data: Any) -> None:
740740
print("POST", arbiter.shapes)
741741
if self.separate_occurred:
742742
print("POST REMOVE", arbiter.shapes)

pymunk/vec2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __repr__(self) -> str:
7272
return "Vec2d(%s, %s)" % (self.x, self.y)
7373

7474
# Addition
75-
def __add__(self, other: Tuple[float, float]) -> "Vec2d": # type: ignore
75+
def __add__(self, other: Tuple[float, float]) -> "Vec2d": # type: ignore[override]
7676
"""Add a Vec2d with another Vec2d or Tuple of size 2
7777
7878
>>> Vec2d(3,4) + Vec2d(1,2)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from setuptools import setup # type: ignore
3+
from setuptools import setup
44

55
packages = ["pymunk", "pymunk.tests", "pymunk.examples"]
66
exclude_package_data = {}

0 commit comments

Comments
 (0)