Skip to content

Commit 4d0dc7e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6c872db commit 4d0dc7e

File tree

4 files changed

+28
-53
lines changed

4 files changed

+28
-53
lines changed

json5/loader.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ def __init__(
4646
self.parse_int: Callable[[str], typing.Any] | None = parse_int
4747
self.parse_constant: Callable[[Literal['-Infinity', 'Infinity', 'NaN']], typing.Any] | None = parse_constant
4848
self.strict: bool = strict
49-
self.object_pairs_hook: None | (
50-
Callable[[list[tuple[str | JsonIdentifier, typing.Any]]], typing.Any]
51-
) = object_pairs_hook
49+
self.object_pairs_hook: None | (Callable[[list[tuple[str | JsonIdentifier, typing.Any]]], typing.Any]) = (
50+
object_pairs_hook
51+
)
5252
self.parse_json5_identifiers: Callable[[JsonIdentifier], typing.Any] | None = parse_json5_identifiers
5353

5454

55-
class JsonIdentifier(str):
56-
...
55+
class JsonIdentifier(str): ...
5756

5857

5958
def load(

json5/model.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ class Value(Node):
133133
pass
134134

135135

136-
class Key(Node):
137-
...
136+
class Key(Node): ...
138137

139138

140139
class JSONObject(Value):
@@ -208,8 +207,7 @@ def __eq__(self, other: Any) -> bool:
208207
return hash(self) == hash(other)
209208

210209

211-
class Number(Value):
212-
...
210+
class Number(Value): ...
213211

214212

215213
class Integer(Number):
@@ -301,12 +299,10 @@ def __init__(
301299
super().__init__(tok=tok, end_tok=tok)
302300

303301

304-
class DoubleQuotedString(String):
305-
...
302+
class DoubleQuotedString(String): ...
306303

307304

308-
class SingleQuotedString(String):
309-
...
305+
class SingleQuotedString(String): ...
310306

311307

312308
class BooleanLiteral(Value):
@@ -348,9 +344,7 @@ def __init__(self, value: str, tok: JSON5Token | None = None, end_tok: JSON5Toke
348344
super().__init__(tok=tok, end_tok=tok) # Comments are always a single token
349345

350346

351-
class LineComment(Comment):
352-
...
347+
class LineComment(Comment): ...
353348

354349

355-
class BlockComment(Comment):
356-
...
350+
class BlockComment(Comment): ...

json5/parser.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def unicode_escape_replace(matchobj: re.Match[str]) -> str:
9797

9898

9999
class T_TokenSlice(Protocol):
100-
def __getitem__(self, item: int) -> JSON5Token:
101-
...
100+
def __getitem__(self, item: int) -> JSON5Token: ...
102101

103102

104103
class T_AnyProduction(Protocol):
@@ -110,8 +109,7 @@ class T_TextProduction(Protocol):
110109
wsc1: list[Comment | str]
111110
value: Value
112111

113-
def __getitem__(self, i: Literal[1]) -> Value:
114-
...
112+
def __getitem__(self, i: Literal[1]) -> Value: ...
115113

116114

117115
class T_FirstKeyValuePairProduction(Protocol):
@@ -122,22 +120,19 @@ class T_FirstKeyValuePairProduction(Protocol):
122120
value: Value
123121
_slice: T_TokenSlice
124122

125-
def __getitem__(self, item: int) -> Key | Value:
126-
...
123+
def __getitem__(self, item: int) -> Key | Value: ...
127124

128125

129126
class T_WSCProduction(Protocol):
130127
_slice: T_TokenSlice
131128

132-
def __getitem__(self, item: Literal[0]) -> str | Comment:
133-
...
129+
def __getitem__(self, item: Literal[0]) -> str | Comment: ...
134130

135131

136132
class T_CommentProduction(Protocol):
137133
_slice: T_TokenSlice
138134

139-
def __getitem__(self, item: Literal[0]) -> str:
140-
...
135+
def __getitem__(self, item: Literal[0]) -> str: ...
141136

142137

143138
class T_KeyValuePairsProduction(Protocol):
@@ -161,8 +156,7 @@ class SubsequentKeyValuePairProduction(Protocol):
161156
class T_FirstArrayValueProduction(Protocol):
162157
_slice: T_TokenSlice
163158

164-
def __getitem__(self, item: Literal[1]) -> Value:
165-
...
159+
def __getitem__(self, item: Literal[1]) -> Value: ...
166160

167161
wsc: list[Comment | str]
168162

@@ -188,20 +182,17 @@ class T_JsonArrayProduction(Protocol):
188182
class T_IdentifierProduction(Protocol):
189183
_slice: T_TokenSlice
190184

191-
def __getitem__(self, item: Literal[0]) -> str:
192-
...
185+
def __getitem__(self, item: Literal[0]) -> str: ...
193186

194187

195188
class T_KeyProduction(Protocol):
196-
def __getitem__(self, item: Literal[1]) -> Identifier | DoubleQuotedString | SingleQuotedString:
197-
...
189+
def __getitem__(self, item: Literal[1]) -> Identifier | DoubleQuotedString | SingleQuotedString: ...
198190

199191

200192
class T_NumberProduction(Protocol):
201193
_slice: T_TokenSlice
202194

203-
def __getitem__(self, item: Literal[0]) -> str:
204-
...
195+
def __getitem__(self, item: Literal[0]) -> str: ...
205196

206197

207198
class T_ValueNumberProduction(Protocol):
@@ -212,22 +203,19 @@ class T_ValueNumberProduction(Protocol):
212203
class T_ExponentNotationProduction(Protocol):
213204
_slice: T_TokenSlice
214205

215-
def __getitem__(self, item: int) -> str:
216-
...
206+
def __getitem__(self, item: int) -> str: ...
217207

218208

219209
class T_StringTokenProduction(Protocol):
220210
_slice: T_TokenSlice
221211

222-
def __getitem__(self, item: Literal[0]) -> str:
223-
...
212+
def __getitem__(self, item: Literal[0]) -> str: ...
224213

225214

226215
class T_StringProduction(Protocol):
227216
_slice: T_TokenSlice
228217

229-
def __getitem__(self, item: Literal[0]) -> DoubleQuotedString | SingleQuotedString:
230-
...
218+
def __getitem__(self, item: Literal[0]) -> DoubleQuotedString | SingleQuotedString: ...
231219

232220

233221
class T_ValueProduction(Protocol):
@@ -246,8 +234,7 @@ def __getitem__(
246234
| Integer
247235
| Float
248236
| NaN
249-
):
250-
...
237+
): ...
251238

252239

253240
T_CallArg = typing.TypeVar('T_CallArg')

tests/test_errors.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,23 @@ def test_loading_comment_raises_runtime_error_default_loader():
2020

2121

2222
def test_loading_unknown_node_raises_error():
23-
class Foo:
24-
...
23+
class Foo: ...
2524

2625
f = Foo()
2726
with pytest.raises(NotImplementedError):
2827
DefaultLoader().load(f)
2928

3029

3130
def test_dumping_unknown_node_raises_error():
32-
class Foo:
33-
...
31+
class Foo: ...
3432

3533
f = Foo()
3634
with pytest.raises(NotImplementedError):
3735
DefaultDumper().dump(f)
3836

3937

4038
def test_known_type_in_wsc_raises_error():
41-
class Foo:
42-
...
39+
class Foo: ...
4340

4441
f = Foo()
4542
model = loads('{foo: "bar"}', loader=ModelLoader())
@@ -53,17 +50,15 @@ class Foo:
5350

5451

5552
def test_modelizing_unknown_object_raises_error():
56-
class Foo:
57-
...
53+
class Foo: ...
5854

5955
f = Foo()
6056
with pytest.raises(NotImplementedError):
6157
modelize(f)
6258

6359

6460
def test_model_dumper_raises_error_for_unknown_node():
65-
class Foo:
66-
...
61+
class Foo: ...
6762

6863
f = Foo()
6964
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)