Skip to content

Commit

Permalink
Add more fixes for mypy type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mangiucugna committed Aug 19, 2024
1 parent c22eeb8 commit 4014630
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "json_repair"
version = "0.28.0"
version = "0.28.1"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
Expand Down
12 changes: 6 additions & 6 deletions src/json_repair/json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def parse_object(self) -> Dict[str, Any]:
# <member> starts with a <string>
key = ""
while self.get_char_at():
key = self.parse_string()
key = str(self.parse_string())

if key != "" or (key == "" and self.get_char_at() == ":"):
# If the string is empty but there is a object divider, we are done here
Expand Down Expand Up @@ -255,7 +255,7 @@ def parse_array(self) -> List[Any]:
self.reset_context()
return arr

def parse_string(self) -> Union[str, JSONReturnType]:
def parse_string(self) -> Union[str, bool, None]:
# <string> is a string of valid characters enclosed in quotes
# i.e. { name: "John" }
# Somehow all weird cases in an invalid JSON happen to be resolved in this function, so be careful here
Expand Down Expand Up @@ -382,7 +382,7 @@ def parse_string(self) -> Union[str, JSONReturnType]:
string_acc += char
self.index += 1
char = self.get_char_at()
if len(string_acc) > 0 and string_acc[-1] == "\\":
if char and len(string_acc) > 0 and string_acc[-1] == "\\":
# This is a special case, if people use real strings this might happen
self.log("Found a stray escape sequence, normalizing it", "info")
string_acc = string_acc[:-1]
Expand Down Expand Up @@ -473,7 +473,7 @@ def parse_string(self) -> Union[str, JSONReturnType]:
"While parsing a string, we a misplaced quote that would have closed the string but has a different meaning here since this is the last element of the object, ignoring it",
"info",
)
string_acc += char
string_acc += str(char)
self.index += 1
char = self.get_char_at()
elif next_c == rstring_delimiter:
Expand Down Expand Up @@ -503,7 +503,7 @@ def parse_string(self) -> Union[str, JSONReturnType]:
"While parsing a string, we a misplaced quote that would have closed the string but has a different meaning here, ignoring it",
"info",
)
string_acc += char
string_acc += str(char)
self.index += 1
char = self.get_char_at()

Expand Down Expand Up @@ -585,7 +585,7 @@ def parse_boolean_or_null(self) -> Union[bool, str, None]:
self.index = starting_index
return ""

def get_char_at(self, count: int = 0) -> Union[str, bool]:
def get_char_at(self, count: int = 0) -> Union[str, Literal[False]]:
# Why not use something simpler? Because try/except in python is a faster alternative to an "if" statement that is often True
try:
return self.json_str[self.index + count]
Expand Down

0 comments on commit 4014630

Please sign in to comment.