1616JSON = ty .Union [ty .Dict [str , "JSON" ], ty .List ["JSON" ], Primitive ]
1717
1818
19- def _is_optional (field : ty .Type ):
19+ def _is_optional (field : ty .Type ) -> bool :
2020 # type hackery incoming
2121 # ty.Optional[T] == ty.Union[T, None]
2222 # since ty.Union[ty.Union[T,U]] = ty.Union[T,U] we can the
@@ -30,7 +30,7 @@ class ArtifactEmitter:
3030 Uses the low level dataclass models for the spec, but should not be used in user code.
3131 """
3232
33- def __init__ (self , writer : Writer ):
33+ def __init__ (self , writer : Writer ) -> None :
3434 self ._seq_lock = threading .Lock ()
3535 self ._seq = 0
3636
@@ -41,7 +41,7 @@ def __init__(self, writer: Writer):
4141 self ._version_emitted = threading .Event ()
4242
4343 @staticmethod
44- def _serialize (artifact : ArtifactType ):
44+ def _serialize (artifact : ArtifactType ) -> str :
4545 def visit (
4646 value : ty .Union [ArtifactType , ty .Dict , ty .List , Primitive ],
4747 formatter : ty .Optional [ty .Callable [[ty .Any ], str ]] = None ,
@@ -56,7 +56,7 @@ def visit(
5656 val = getattr (value , field .name )
5757
5858 if val is None :
59- if not _is_optional (field .type ):
59+ if not _is_optional (ty . cast ( ty . Type , field .type ) ):
6060 # TODO: fix exception text/type
6161 raise RuntimeError ("unacceptable none where not optional" )
6262
0 commit comments