Skip to content

Commit ab28a90

Browse files
typing for deep_transform
1 parent 67defbc commit ab28a90

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

schemascii/utils.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,32 @@ def iterate_line(p1: complex, p2: complex, step: float = 1.0):
254254
yield point
255255

256256

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):
258278
"""Transform the point or points first by translating by origin,
259279
then rotating by theta. Return an identical data structure,
260280
but with the transformed points substituted.
261-
262-
TODO: add type statements for the data argument. This is really weird.
263281
"""
264-
if isinstance(data, list | tuple):
282+
if isinstance(data, (list, tuple)):
265283
return [deep_transform(d, origin, theta) for d in data]
266284
if isinstance(data, complex):
267285
return (origin
@@ -574,3 +592,4 @@ def sort_for_flags(terminals: list[Terminal],
574592
for x in range(n):
575593
pts.append(force_int(rect(n, 2 * pi * x / n)))
576594
pprint.pprint(sort_counterclockwise(pts))
595+
print(_DT_Struct)

0 commit comments

Comments
 (0)