Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(evals): a JSON container subclass encodes as the mapping it wraps

Aashishdb74aae23067
diff --git a/laya/_agreement.py b/laya/_agreement.py
index 3eb4c506..c46ab2c9 100644
--- a/laya/_agreement.py
+++ b/laya/_agreement.py
@@ -24,14 +24,23 @@ def _text(value: Any, where: str) -> None:
def _json(value: Any, where: str) -> str:
- """Strict JSON, preserving object order because it can change model inputs."""
+ """Strict JSON, preserving object order because it can change model inputs.
+
+ Containers are matched by `isinstance`, scalars by exact type. `json.dumps` writes a `dict` or
+ `list` subclass as the very object or array it wraps -- an `OrderedDict`, a `defaultdict`, a
+ `Counter`, or anything read back with `object_pairs_hook=OrderedDict`, the way a caller keeps the
+ key order this module fingerprints -- encodes byte-for-byte as the mapping it equals and hashes to
+ the same fingerprint, so matching the encoder here refuses nothing the encoder would have taken.
+ Scalars are matched by exact type: `numpy.float64` and `numpy.str_` do encode, but as a type the
+ writer did not declare, and `numpy.int64` and `numpy.bool_` raise `TypeError` in the encoder.
+ """
def check(item):
- if type(item) is dict:
+ if isinstance(item, dict):
for key, child in item.items():
if not isinstance(key, str):
raise ValueError("object keys must be strings")
check(child)
- elif type(item) is list:
+ elif isinstance(item, list):
for child in item:
check(child)
elif type(item) not in (str, int, float, bool, type(None)):