preliminary UnionNode implementation #913
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements support for unions of primitive types (i.e. unions of
int
,float
,bool
,str
,bytes
, andNone
).A few notes:
Union
can be freely mixed withOptional
andNone
. For example, all of the following are equivalent:Optional[Union[int, str]]
Union[Optional[int], str]
Union[int, str, None]
Union[int, str, type(None)]
List[Union[int, str]]
, orDict[int, Union[str, bytes]]
) are supported.Union[List[str], Dict[str, str], MyStructuredConfig]
) are not yet supported. This will come in a followup PR.Here is a demo of the API:
Implementation Notes:
UnionNode
is a "pass-through" node. That means most validation logic is delegated to a child node.Container._get_child
which parallelsContainer._get_node
. The difference between these methods is that_get_child
automatically "passes over" Unions. Similarly, I've introducedNode._get_parent_container()
, which is similar toNode._get_parent()
except that it passes over union nodes in the parent heirarchy.TODO before merging this
_get_parent
vs_get_parent_container
throughout the codebase._get_node
vs_get_child
throughout the codebase.