16
16
JSON = ty .Union [ty .Dict [str , "JSON" ], ty .List ["JSON" ], Primitive ]
17
17
18
18
19
- def _is_optional (field : ty .Type ):
19
+ def _is_optional (field : ty .Type ) -> bool :
20
20
# type hackery incoming
21
21
# ty.Optional[T] == ty.Union[T, None]
22
22
# since ty.Union[ty.Union[T,U]] = ty.Union[T,U] we can the
@@ -30,7 +30,7 @@ class ArtifactEmitter:
30
30
Uses the low level dataclass models for the spec, but should not be used in user code.
31
31
"""
32
32
33
- def __init__ (self , writer : Writer ):
33
+ def __init__ (self , writer : Writer ) -> None :
34
34
self ._seq_lock = threading .Lock ()
35
35
self ._seq = 0
36
36
@@ -41,7 +41,7 @@ def __init__(self, writer: Writer):
41
41
self ._version_emitted = threading .Event ()
42
42
43
43
@staticmethod
44
- def _serialize (artifact : ArtifactType ):
44
+ def _serialize (artifact : ArtifactType ) -> str :
45
45
def visit (
46
46
value : ty .Union [ArtifactType , ty .Dict , ty .List , Primitive ],
47
47
formatter : ty .Optional [ty .Callable [[ty .Any ], str ]] = None ,
@@ -56,7 +56,7 @@ def visit(
56
56
val = getattr (value , field .name )
57
57
58
58
if val is None :
59
- if not _is_optional (field .type ):
59
+ if not _is_optional (ty . cast ( ty . Type , field .type ) ):
60
60
# TODO: fix exception text/type
61
61
raise RuntimeError ("unacceptable none where not optional" )
62
62
0 commit comments