Skip to content

Commit cfa6940

Browse files
(api-break) sequenceの出力に用いる型を指定する選択肢を削除
1 parent 9ed31e0 commit cfa6940

File tree

2 files changed

+23
-46
lines changed

2 files changed

+23
-46
lines changed

src/asyncgui_ext/clock.py

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ async def interpolate_scalar(self, start, end, *, duration, step=0, transition=_
341341
.. versionadded:: 0.5.2
342342
'''
343343

344-
async def interpolate_sequence(self, start, end, *, duration, step=0, transition=_linear, output_type=tuple) -> AsyncIterator:
344+
async def interpolate_sequence(self, start, end, *, duration, step=0, transition=_linear) -> AsyncIterator:
345345
'''
346-
Same as :meth:`interpolate_scalar` except this one is for sequence type.
346+
Same as :meth:`interpolate_scalar` except this one is for sequence types.
347347
348348
.. code-block::
349349
@@ -353,37 +353,37 @@ async def interpolate_sequence(self, start, end, *, duration, step=0, transition
353353
============ ==========
354354
elapsed time output
355355
============ ==========
356-
0 (0, 50)
357-
30 (30, 65)
358-
60 (60, 80)
359-
90 (90, 95)
360-
**120** (100, 100)
356+
0 [0, 50]
357+
30 [30, 65]
358+
60 [60, 80]
359+
90 [90, 95]
360+
**120** [100, 100]
361361
============ ==========
362362
'''
363363
zip_ = zip
364-
slope = tuple(end_elem - start_elem for end_elem, start_elem in zip_(end, start))
364+
slope = [end_elem - start_elem for end_elem, start_elem in zip_(end, start)]
365365

366366
p = transition(0.)
367-
yield output_type(p * slope_elem + start_elem for slope_elem, start_elem in zip_(slope, start))
367+
yield [p * slope_elem + start_elem for slope_elem, start_elem in zip_(slope, start)]
368368

369369
if duration:
370370
async for p in self.anim_with_ratio(step=step, base=duration):
371371
if p >= 1.0:
372372
break
373373
p = transition(p)
374-
yield output_type(p * slope_elem + start_elem for slope_elem, start_elem in zip_(slope, start))
374+
yield [p * slope_elem + start_elem for slope_elem, start_elem in zip_(slope, start)]
375375
else:
376376
await self.sleep(0)
377377

378378
p = transition(1.)
379-
yield output_type(p * slope_elem + start_elem for slope_elem, start_elem in zip_(slope, start))
379+
yield [p * slope_elem + start_elem for slope_elem, start_elem in zip_(slope, start)]
380380

381381
interpolate_seq = interpolate_sequence
382382
'''
383383
An alias for :meth:`interpolate_sequence`.
384384
'''
385385

386-
def _update(setattr, zip, min, obj, duration, transition, output_seq_type, anim_params, task, p_time, dt):
386+
def _update(setattr, zip, min, obj, duration, transition, anim_params, task, p_time, dt):
387387
time = p_time[0] + dt
388388
p_time[0] = time
389389

@@ -394,10 +394,10 @@ def _update(setattr, zip, min, obj, duration, transition, output_seq_type, anim_
394394
# apply progression on obj
395395
for attr_name, org_value, slope, is_seq in anim_params:
396396
if is_seq:
397-
new_value = output_seq_type(
397+
new_value = [
398398
slope_elem * t + org_elem
399399
for org_elem, slope_elem in zip(org_value, slope)
400-
)
400+
]
401401
setattr(obj, attr_name, new_value)
402402
else:
403403
setattr(obj, attr_name, slope * t + org_value)
@@ -410,26 +410,26 @@ def _update(setattr, zip, min, obj, duration, transition, output_seq_type, anim_
410410

411411
@types.coroutine
412412
def _anim_attrs(
413-
self, obj, duration, step, transition, output_seq_type, animated_properties,
413+
self, obj, duration, step, transition, animated_properties,
414414
getattr=getattr, isinstance=isinstance, tuple=tuple, partial=partial, native_seq_types=(tuple, list),
415415
zip=zip, _update=_update,
416416
_current_task=_current_task, _sleep_forever=_sleep_forever, /):
417417
# get current values & calculate slopes
418-
anim_params = tuple(
418+
anim_params = [
419419
(
420420
org_value := getattr(obj, attr_name),
421421
is_seq := isinstance(org_value, native_seq_types),
422422
(
423423
org_value := tuple(org_value),
424-
slope := tuple(goal_elem - org_elem for goal_elem, org_elem in zip(goal_value, org_value)),
424+
slope := [goal_elem - org_elem for goal_elem, org_elem in zip(goal_value, org_value)],
425425
) if is_seq else (slope := goal_value - org_value),
426426
) and (attr_name, org_value, slope, is_seq, )
427427
for attr_name, goal_value in animated_properties.items()
428-
)
428+
]
429429

430430
try:
431431
event = self.schedule_interval(
432-
partial(_update, obj, duration, transition, output_seq_type, anim_params, (yield _current_task)[0][0], [0, ]),
432+
partial(_update, obj, duration, transition, anim_params, (yield _current_task)[0][0], [0, ]),
433433
step,
434434
)
435435
yield _sleep_forever
@@ -438,8 +438,7 @@ def _anim_attrs(
438438

439439
del _update
440440

441-
def anim_attrs(self, obj, *, duration, step=0, transition=_linear, output_seq_type=tuple,
442-
**animated_properties) -> Awaitable:
441+
def anim_attrs(self, obj, *, duration, step=0, transition=_linear, **animated_properties) -> Awaitable:
443442
'''
444443
Animates attibutes of any object.
445444
@@ -449,22 +448,14 @@ def anim_attrs(self, obj, *, duration, step=0, transition=_linear, output_seq_ty
449448
450449
obj = types.SimpleNamespace(x=0, size=(200, 300))
451450
await clock.anim_attrs(obj, x=100, size=(400, 400), duration=2)
452-
453-
The ``output_seq_type`` parameter.
454-
455-
.. code-block::
456-
457-
obj = types.SimpleNamespace(size=(200, 300))
458-
await clock.anim_attrs(obj, size=(400, 400), duration=2, output_seq_type=list)
459-
assert type(obj.size) is list
460451
'''
461-
return self._anim_attrs(obj, duration, step, transition, output_seq_type, animated_properties)
452+
return self._anim_attrs(obj, duration, step, transition, animated_properties)
462453

463-
def anim_attrs_abbr(self, obj, *, d, s=0, t=_linear, output_seq_type=tuple, **animated_properties) -> Awaitable:
454+
def anim_attrs_abbr(self, obj, *, d, s=0, t=_linear, **animated_properties) -> Awaitable:
464455
'''
465456
:meth:`anim_attrs` cannot animate attributes named ``step``, ``duration`` and ``transition`` but this one can.
466457
'''
467-
return self._anim_attrs(obj, d, s, t, output_seq_type, animated_properties)
458+
return self._anim_attrs(obj, d, s, t, animated_properties)
468459

469460

470461
class _repeat_sleeping:

tests/clock/test_anim_attrs.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,3 @@ def test_sequence(clock):
3838
clock.tick(30)
3939
assert obj.pos == approx([100, 0])
4040
assert task.finished
41-
42-
43-
@pytest.mark.parametrize('output_seq_type', [list, tuple])
44-
def test_seq_type_parameter(clock, output_seq_type):
45-
from types import SimpleNamespace
46-
import asyncgui
47-
48-
obj = SimpleNamespace(size=(0, 0), pos=[0, 0])
49-
task = asyncgui.start(clock.anim_attrs(obj, size=[10, 10], pos=(10, 10), duration=10, output_seq_type=output_seq_type))
50-
clock.tick(0)
51-
assert type(obj.size) is output_seq_type
52-
assert type(obj.pos) is output_seq_type
53-
assert not task.finished
54-
task.cancel()

0 commit comments

Comments
 (0)