This test fails without this change (with a frustrating validation error):
from dataclasses import dataclass
from typing import Tuple
from hologram import JsonSchemaMixin
@dataclass
class TupleMember(JsonSchemaMixin):
a: int
@dataclass
class TupleMemberSecondHolder(JsonSchemaMixin):
member: Tuple[str, TupleMember]
TupleMemberSecondHolder.from_dict({"member": ["a", {"a": 1}]})
hologram 0.0.6 only checks the first value in a Tuple's __args__, but tuples can be of two forms:
Tuple[T, ...] -> A tuple of any length with members of type T
Tuple[T1, T2, T3] A 3-tuple, where the first member is of type T1, the second T2, and the third T2.
In the second form, tuple members beyond the first are not captured during schema generation.
hologram 0.0.6 also only checks the first member of a Union if one member is None (that's what is_optional checks). That generally works in the case of typing.Optional[T], as it becomes typing.Union[T, None]. But hologram does not handle weirder constructions like typing.Optional[typing.Union[None, T]] gracefully - that one gets stuck as typing.Union[None, T], so hologram doesn't generate schema information for T. The fix for this is to just remove all special handling of options when collecting field descriptions - the None values just fall through and you collect all the arguments.
This test fails without this change (with a frustrating validation error):
hologram 0.0.6 only checks the first value in a
Tuple
's__args__
, but tuples can be of two forms:Tuple[T, ...]
-> A tuple of any length with members of typeT
Tuple[T1, T2, T3]
A 3-tuple, where the first member is of typeT1
, the secondT2
, and the thirdT2
.In the second form, tuple members beyond the first are not captured during schema generation.
hologram 0.0.6 also only checks the first member of a
Union
if one member isNone
(that's whatis_optional
checks). That generally works in the case oftyping.Optional[T]
, as it becomestyping.Union[T, None]
. But hologram does not handle weirder constructions liketyping.Optional[typing.Union[None, T]]
gracefully - that one gets stuck astyping.Union[None, T]
, so hologram doesn't generate schema information forT
. The fix for this is to just remove all special handling of options when collecting field descriptions - theNone
values just fall through and you collect all the arguments.