Skip to content

Commit 9f9b9c3

Browse files
committed
Fix some types for mypy 1.13
Signed-off-by: mimir-d <[email protected]>
1 parent 32a3c58 commit 9f9b9c3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/ocptv/output/emit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
JSON = 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

src/ocptv/output/runtime_checks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def __str__(self):
119119

120120

121121
def _check_type_any(obj: CheckedValue, hint: ty.Type, trace: ty.List[str]):
122-
type_origin = get_origin(hint)
123-
type_args = get_args(hint)
122+
type_origin = ty.cast(ty.Type | None, get_origin(hint))
123+
type_args = ty.cast(ty.Tuple[ty.Type, ...], get_args(hint))
124124

125125
if type_origin is list:
126126
# generic type: typ == ty.List[...]
@@ -186,7 +186,7 @@ def _check_type_any(obj: CheckedValue, hint: ty.Type, trace: ty.List[str]):
186186
elif dc.is_dataclass(obj):
187187
for field in dc.fields(obj):
188188
subtrace = trace + [f"{obj.__class__.__name__}.{field.name}"]
189-
_check_type_any(getattr(obj, field.name), field.type, subtrace)
189+
_check_type_any(getattr(obj, field.name), ty.cast(ty.Type, field.type), subtrace)
190190

191191
elif not isinstance(obj, hint):
192192
raise TypeCheckError(obj, expected=hint.__name__, trace=trace)

0 commit comments

Comments
 (0)