@@ -15,18 +15,40 @@ class _LateBound(NamedTuple):
15
15
actual : Any
16
16
17
17
18
- def __ (o : _T | Iterator [_V ]) -> _T | _V :
18
+ def late (o : _T | Iterator [_V ]) -> _T | _V :
19
19
if isinstance (o , int | float | str | bool | bytes | bytearray | frozenset ):
20
20
return o # type: ignore
21
+
22
+ actual : Any = None
23
+ if isinstance (o , list ):
24
+ actual = [late (value ) for value in o ]
25
+ elif isinstance (o , dict ):
26
+ actual = {name : late (value ) for name , value in o .items ()}
27
+ elif isinstance (o , set ):
28
+ actual = {late (value ) for value in o }
21
29
else :
22
- return _LateBound (actual = o ) # type: ignore
30
+ actual = o
31
+ return _LateBound (actual = actual ) # type: ignore
32
+
33
+
34
+ __ = late
23
35
24
36
25
37
def _lateargs (func : Callable , ** kwargs ) -> dict [str , Any ]:
26
38
27
39
def resolve_default (value ):
28
40
if inspect .isgenerator (value ):
29
41
return next (value )
42
+ if inspect .isfunction (value ):
43
+ return value ()
44
+ if isinstance (value , _LateBound ):
45
+ return resolve_default (value .actual )
46
+ if isinstance (value , list ):
47
+ return [resolve_default (x ) for x in value ]
48
+ if isinstance (value , dict ):
49
+ return {name : resolve_default (x ) for name , x in value .items ()}
50
+ if isinstance (value , set ):
51
+ return {resolve_default (x ) for x in value }
30
52
return copy .copy (value )
31
53
32
54
lateargs = {
0 commit comments