diff --git a/json5/loader.py b/json5/loader.py index a5e7f04..b7cac63 100644 --- a/json5/loader.py +++ b/json5/loader.py @@ -46,14 +46,13 @@ def __init__( self.parse_int: Callable[[str], typing.Any] | None = parse_int self.parse_constant: Callable[[Literal['-Infinity', 'Infinity', 'NaN']], typing.Any] | None = parse_constant self.strict: bool = strict - self.object_pairs_hook: None | ( - Callable[[list[tuple[str | JsonIdentifier, typing.Any]]], typing.Any] - ) = object_pairs_hook + self.object_pairs_hook: None | (Callable[[list[tuple[str | JsonIdentifier, typing.Any]]], typing.Any]) = ( + object_pairs_hook + ) self.parse_json5_identifiers: Callable[[JsonIdentifier], typing.Any] | None = parse_json5_identifiers -class JsonIdentifier(str): - ... +class JsonIdentifier(str): ... def load( diff --git a/json5/model.py b/json5/model.py index 17f2aae..017890f 100644 --- a/json5/model.py +++ b/json5/model.py @@ -133,8 +133,7 @@ class Value(Node): pass -class Key(Node): - ... +class Key(Node): ... class JSONObject(Value): @@ -208,8 +207,7 @@ def __eq__(self, other: Any) -> bool: return hash(self) == hash(other) -class Number(Value): - ... +class Number(Value): ... class Integer(Number): @@ -301,12 +299,10 @@ def __init__( super().__init__(tok=tok, end_tok=tok) -class DoubleQuotedString(String): - ... +class DoubleQuotedString(String): ... -class SingleQuotedString(String): - ... +class SingleQuotedString(String): ... class BooleanLiteral(Value): @@ -348,9 +344,7 @@ def __init__(self, value: str, tok: JSON5Token | None = None, end_tok: JSON5Toke super().__init__(tok=tok, end_tok=tok) # Comments are always a single token -class LineComment(Comment): - ... +class LineComment(Comment): ... -class BlockComment(Comment): - ... +class BlockComment(Comment): ... diff --git a/json5/parser.py b/json5/parser.py index bf36142..008c760 100644 --- a/json5/parser.py +++ b/json5/parser.py @@ -97,8 +97,7 @@ def unicode_escape_replace(matchobj: re.Match[str]) -> str: class T_TokenSlice(Protocol): - def __getitem__(self, item: int) -> JSON5Token: - ... + def __getitem__(self, item: int) -> JSON5Token: ... class T_AnyProduction(Protocol): @@ -110,8 +109,7 @@ class T_TextProduction(Protocol): wsc1: list[Comment | str] value: Value - def __getitem__(self, i: Literal[1]) -> Value: - ... + def __getitem__(self, i: Literal[1]) -> Value: ... class T_FirstKeyValuePairProduction(Protocol): @@ -122,22 +120,19 @@ class T_FirstKeyValuePairProduction(Protocol): value: Value _slice: T_TokenSlice - def __getitem__(self, item: int) -> Key | Value: - ... + def __getitem__(self, item: int) -> Key | Value: ... class T_WSCProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[0]) -> str | Comment: - ... + def __getitem__(self, item: Literal[0]) -> str | Comment: ... class T_CommentProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[0]) -> str: - ... + def __getitem__(self, item: Literal[0]) -> str: ... class T_KeyValuePairsProduction(Protocol): @@ -161,8 +156,7 @@ class SubsequentKeyValuePairProduction(Protocol): class T_FirstArrayValueProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[1]) -> Value: - ... + def __getitem__(self, item: Literal[1]) -> Value: ... wsc: list[Comment | str] @@ -188,20 +182,17 @@ class T_JsonArrayProduction(Protocol): class T_IdentifierProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[0]) -> str: - ... + def __getitem__(self, item: Literal[0]) -> str: ... class T_KeyProduction(Protocol): - def __getitem__(self, item: Literal[1]) -> Identifier | DoubleQuotedString | SingleQuotedString: - ... + def __getitem__(self, item: Literal[1]) -> Identifier | DoubleQuotedString | SingleQuotedString: ... class T_NumberProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[0]) -> str: - ... + def __getitem__(self, item: Literal[0]) -> str: ... class T_ValueNumberProduction(Protocol): @@ -212,22 +203,19 @@ class T_ValueNumberProduction(Protocol): class T_ExponentNotationProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: int) -> str: - ... + def __getitem__(self, item: int) -> str: ... class T_StringTokenProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[0]) -> str: - ... + def __getitem__(self, item: Literal[0]) -> str: ... class T_StringProduction(Protocol): _slice: T_TokenSlice - def __getitem__(self, item: Literal[0]) -> DoubleQuotedString | SingleQuotedString: - ... + def __getitem__(self, item: Literal[0]) -> DoubleQuotedString | SingleQuotedString: ... class T_ValueProduction(Protocol): @@ -246,8 +234,7 @@ def __getitem__( | Integer | Float | NaN - ): - ... + ): ... T_CallArg = typing.TypeVar('T_CallArg') diff --git a/tests/test_errors.py b/tests/test_errors.py index a269481..1048f7d 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -20,8 +20,7 @@ def test_loading_comment_raises_runtime_error_default_loader(): def test_loading_unknown_node_raises_error(): - class Foo: - ... + class Foo: ... f = Foo() with pytest.raises(NotImplementedError): @@ -29,8 +28,7 @@ class Foo: def test_dumping_unknown_node_raises_error(): - class Foo: - ... + class Foo: ... f = Foo() with pytest.raises(NotImplementedError): @@ -38,8 +36,7 @@ class Foo: def test_known_type_in_wsc_raises_error(): - class Foo: - ... + class Foo: ... f = Foo() model = loads('{foo: "bar"}', loader=ModelLoader()) @@ -53,8 +50,7 @@ class Foo: def test_modelizing_unknown_object_raises_error(): - class Foo: - ... + class Foo: ... f = Foo() with pytest.raises(NotImplementedError): @@ -62,8 +58,7 @@ class Foo: def test_model_dumper_raises_error_for_unknown_node(): - class Foo: - ... + class Foo: ... f = Foo() with pytest.raises(NotImplementedError):