Skip to content

Commit

Permalink
Minor refactor of internal variable names (#179)
Browse files Browse the repository at this point in the history
Minor change to avoid shadowing type and to pop the $type from the dict
  • Loading branch information
eyurtsev authored Jun 27, 2023
1 parent 94d6bcb commit 5ebbebe
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions kor/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ class ExtractionSchemaNode(AbstractSchemaNode, abc.ABC):

@classmethod
def parse_obj(cls: Type[ExtractionSchemaNode], data: dict) -> ExtractionSchemaNode:
type = data.get("$type")
if type is None:
"""Parse an object."""
type_ = data.pop("$type", None)
if type_ is None:
raise ValueError("Need to specify type ($type)")
for sub in cls.__subclasses__():
if type == sub.__name__:
if type_ == sub.__name__:
return sub(**data)
raise TypeError(f"Unknown sub-type: {type}")
raise TypeError(f"Unknown sub-type: {type_}")

@classmethod
def validate(cls: Type[ExtractionSchemaNode], v: Any) -> ExtractionSchemaNode:
Expand Down

0 comments on commit 5ebbebe

Please sign in to comment.