diff --git a/.gitignore b/.gitignore index 512a5e1..c66ceac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ dist/ /**/__pycache__/ + +.*sw* diff --git a/latch_data_validation/data_validation.py b/latch_data_validation/data_validation.py index 0f76169..e154491 100644 --- a/latch_data_validation/data_validation.py +++ b/latch_data_validation/data_validation.py @@ -1,8 +1,9 @@ import collections.abc import dataclasses +import sys +import typing from enum import Enum from itertools import chain -import sys from types import FrameType, NoneType, UnionType from typing import ( Any, @@ -19,7 +20,6 @@ get_origin, get_type_hints, ) -import typing from opentelemetry.trace import get_tracer @@ -103,7 +103,7 @@ def explain(self, indent: str = ""): pretty_msg = prettify( self.msg, - add_colon=True + add_colon=True, # add_colon=len(self.children) > 0 or len(self.details) > 0 ) res = f"{indent}{pretty_msg}\n" @@ -196,7 +196,8 @@ def untraced_validate(x: JsonValue, cls: type[T]) -> T: for f in dataclasses.fields(cls): schema_fields.add(f.name) if f.name not in x: - missing_class_fields.append(f) + if get_origin(f.type) != Union and NoneType not in get_args(f.type): + missing_class_fields.append(f) continue try: @@ -459,7 +460,6 @@ def untraced_validate(x: JsonValue, cls: type[T]) -> T: raise DataValidationError("[!Internal Error!] unknown type", x, cls) - def validate(x: JsonValue, cls: type[T]) -> T: with tracer.start_as_current_span( validate.__qualname__,