@@ -254,14 +254,32 @@ def iterate_line(p1: complex, p2: complex, step: float = 1.0):
254
254
yield point
255
255
256
256
257
- def deep_transform (data , origin : complex , theta : float ):
257
+ # __future__ annotations does no good here if we
258
+ # don't have 3.12's type statement!!
259
+ _DT_Struct = list ["_DT_Struct" ] | tuple ["_DT_Struct" ] | complex
260
+
261
+
262
+ @typing .overload
263
+ def deep_transform (data : list [_DT_Struct ], origin : complex ,
264
+ theta : float ) -> list [_DT_Struct ]: ...
265
+
266
+
267
+ @typing .overload
268
+ def deep_transform (data : tuple [_DT_Struct ], origin : complex ,
269
+ theta : float ) -> tuple [_DT_Struct ]: ...
270
+
271
+
272
+ @typing .overload
273
+ def deep_transform (data : complex , origin : complex ,
274
+ theta : float ) -> complex : ...
275
+
276
+
277
+ def deep_transform (data : _DT_Struct , origin : complex , theta : float ):
258
278
"""Transform the point or points first by translating by origin,
259
279
then rotating by theta. Return an identical data structure,
260
280
but with the transformed points substituted.
261
-
262
- TODO: add type statements for the data argument. This is really weird.
263
281
"""
264
- if isinstance (data , list | tuple ):
282
+ if isinstance (data , ( list , tuple ) ):
265
283
return [deep_transform (d , origin , theta ) for d in data ]
266
284
if isinstance (data , complex ):
267
285
return (origin
@@ -574,3 +592,4 @@ def sort_for_flags(terminals: list[Terminal],
574
592
for x in range (n ):
575
593
pts .append (force_int (rect (n , 2 * pi * x / n )))
576
594
pprint .pprint (sort_counterclockwise (pts ))
595
+ print (_DT_Struct )
0 commit comments