Skip to content

Commit e414f46

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

File tree

5 files changed

+35
-60
lines changed

5 files changed

+35
-60
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: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class KeyValuePair(NamedTuple):
4141
value: Value
4242

4343

44-
def walk(root: Node) -> typing.Generator[Node, None, None]:
44+
def walk(root: Node) -> typing.Generator[Node]:
4545
todo = deque([root])
4646
while todo:
4747
node: Node = todo.popleft()
4848
todo.extend(iter_child_nodes(node))
4949
yield node
5050

5151

52-
def iter_child_nodes(node: Node) -> typing.Generator[Node, None, None]:
52+
def iter_child_nodes(node: Node) -> typing.Generator[Node]:
5353
for attr, value in iter_fields(node):
5454
if isinstance(value, Node):
5555
yield value
@@ -59,7 +59,7 @@ def iter_child_nodes(node: Node) -> typing.Generator[Node, None, None]:
5959
yield item
6060

6161

62-
def iter_fields(node: Node) -> typing.Generator[tuple[str, Any], None, None]:
62+
def iter_fields(node: Node) -> typing.Generator[tuple[str, Any]]:
6363
for field_name in node._fields:
6464
try:
6565
value = getattr(node, field_name)
@@ -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: 14 additions & 27 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')
@@ -642,7 +629,7 @@ class tok:
642629
self.errors.append(JSON5DecodeError('Expecting value. Received unexpected EOF', None))
643630
return None
644631

645-
def _token_gen(self, tokens: typing.Iterable[JSON5Token]) -> typing.Generator[JSON5Token, None, None]:
632+
def _token_gen(self, tokens: typing.Iterable[JSON5Token]) -> typing.Generator[JSON5Token]:
646633
for tok in tokens:
647634
self.last_token = tok
648635
self.seen_tokens.append(tok)

json5/tokenizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class JSONLexer(Lexer): # type: ignore[misc]
9191
OCTAL, # Not allowed, but we capture as a token to raise error later
9292
}
9393

94-
def tokenize(self, text: str, lineno: int = 1, index: int = 0) -> Generator[JSON5Token, None, None]:
94+
def tokenize(self, text: str, lineno: int = 1, index: int = 0) -> Generator[JSON5Token]:
9595
for tok in super().tokenize(text, lineno, index):
9696
tok = JSON5Token(tok, text)
9797
yield tok
@@ -147,13 +147,13 @@ def error(self, t: JSON5Token) -> NoReturn:
147147
raise JSON5DecodeError(f'Illegal character {t.value[0]!r} at index {self.index}', None)
148148

149149

150-
def tokenize(text: str) -> Generator[JSON5Token, None, None]:
150+
def tokenize(text: str) -> Generator[JSON5Token]:
151151
lexer = JSONLexer()
152152
tokens = lexer.tokenize(text)
153153
return tokens
154154

155155

156-
def reversed_enumerate(tokens: typing.Sequence[JSON5Token]) -> typing.Generator[tuple[int, JSON5Token], None, None]:
156+
def reversed_enumerate(tokens: typing.Sequence[JSON5Token]) -> typing.Generator[tuple[int, JSON5Token]]:
157157
for i in reversed(range(len(tokens))):
158158
tok = tokens[i]
159159
yield i, tok

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)