Skip to content

Commit cf5c255

Browse files
committed
Selfie should accept any function as a camera.
1 parent 8810043 commit cf5c255

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

python/selfie-lib/selfie_lib/Selfie.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, TypeVar, overload
1+
from typing import Any, Callable, TypeVar, overload
22

33
from .Lens import Camera
44
from .SelfieImplementations import BinarySelfie, DiskSelfie, ReprSelfie, StringSelfie
@@ -28,10 +28,18 @@ def expect_selfie(actual: T) -> ReprSelfie[T]: ...
2828
def expect_selfie(actual: T, camera: Camera[T]) -> StringSelfie: ...
2929

3030

31+
@overload
32+
def expect_selfie(actual: T, camera: Callable[[T], Snapshot]) -> StringSelfie: ...
33+
34+
3135
def expect_selfie(actual: Any, camera: Any = None) -> DiskSelfie:
3236
disk_storage = _selfieSystem().disk_thread_local()
3337
if camera is not None:
34-
return StringSelfie(camera.snapshot(actual), disk_storage)
38+
if isinstance(camera, Camera):
39+
actual_snapshot = camera.snapshot(actual)
40+
else:
41+
actual_snapshot = camera(actual)
42+
return StringSelfie(actual_snapshot, disk_storage)
3543
elif isinstance(actual, str):
3644
return StringSelfie(Snapshot.of(actual), disk_storage)
3745
elif isinstance(actual, Snapshot):

0 commit comments

Comments
 (0)