Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 8, 2024
1 parent d100dbc commit 01fb5dc
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions znsocket/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,34 @@ def _encode(self, data: t.Any) -> str:
if self.converter is not None:
try:
return json.dumps(
data, cls=znjson.ZnEncoder.from_converters(self.converter), allow_nan=False
data,
cls=znjson.ZnEncoder.from_converters(self.converter),
allow_nan=False,
)
except ValueError:
if self.convert_nan:
value = json.dumps(
data, cls=znjson.ZnEncoder.from_converters(self.converter), allow_nan=True
data,
cls=znjson.ZnEncoder.from_converters(self.converter),
allow_nan=True,
)
return (
value.replace("NaN", "null")
.replace("-Infinity", "null")
.replace("Infinity", "null")
)
return value.replace("NaN", "null").replace("-Infinity", "null").replace("Infinity", "null")
raise

try:
return json.dumps(data, allow_nan=False)
except ValueError:
if self.convert_nan:
value = json.dumps(data, allow_nan=True)
return value.replace("NaN", "null").replace("-Infinity", "null").replace("Infinity", "null")
return (
value.replace("NaN", "null")
.replace("-Infinity", "null")
.replace("Infinity", "null")
)
raise


Expand Down Expand Up @@ -136,8 +148,8 @@ def __getitem__(self, index: int | list | slice) -> t.Any | list[t.Any]:
for value in data:
if value is None:
raise IndexError("list index out of range")
item = _decode(self, value)

item = _decode(self, value)
if isinstance(item, str):
if item.startswith("znsocket.List:"):
key = item.split(":", 1)[1]
Expand Down

0 comments on commit 01fb5dc

Please sign in to comment.