Skip to content

Commit

Permalink
Fixed some lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
noamgat committed Oct 15, 2023
1 parent c1e2d61 commit 8216f39
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lmformatenforcer/jsonschemaparser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from copy import deepcopy
import enum
from typing import Any, List, Optional, Union

from lmformatenforcer.consts import COMPLETE_ALPHABET
Expand All @@ -9,14 +10,20 @@
from .consts import COMPLETE_ALPHABET

class JsonSchemaParser(CharacterLevelParser):
def __init__(self, json_schema: Union[dict, JsonSchemaObject], existing_stack: List[Any] = None):
object_stack: List['BaseParsingState']
model_class: JsonSchemaObject

def __init__(self, json_schema: Union[dict, JsonSchemaObject], existing_stack: Optional[List['BaseParsingState']] = None):
self.model_class = json_schema if isinstance(json_schema, JsonSchemaObject) else JsonSchemaObject(**json_schema)
self.object_stack: 'List[BaseParsingState]' = existing_stack or [ObjectParsingState(self.model_class, self)]
if existing_stack is None:
self.object_stack = [ObjectParsingState(self.model_class, self)]
else:
self.object_stack = existing_stack

def __deepcopy__(self, memo):
# Avoid cloning the model class, since it is immutable
for parser in self.object_stack:
parser.root = None
parser.root = None # type: ignore
clone = JsonSchemaParser(self.model_class, deepcopy(self.object_stack, memo))
for parser in self.object_stack:
parser.root = self
Expand Down Expand Up @@ -72,7 +79,7 @@ def can_end(self) -> bool:
raise NotImplementedError()


class ObjectParsingStage:
class ObjectParsingStage(enum.Enum):
START_OBJECT = "StartObject"
PARSING_KEY_OR_END = "ParsingKey"
PARSING_VALUE = "ParsingValue"
Expand Down

0 comments on commit 8216f39

Please sign in to comment.