From 5ebbebe8c718e99129a7b196e3d98ed06d6eef37 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Tue, 27 Jun 2023 17:40:06 -0400 Subject: [PATCH] Minor refactor of internal variable names (#179) Minor change to avoid shadowing type and to pop the $type from the dict --- kor/nodes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kor/nodes.py b/kor/nodes.py index eeb3cd1..613603a 100644 --- a/kor/nodes.py +++ b/kor/nodes.py @@ -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: