Skip to content

Commit fa8f9b5

Browse files
committed
Minor changes as suggested by ruff
1 parent 76975cf commit fa8f9b5

File tree

14 files changed

+47
-26
lines changed

14 files changed

+47
-26
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ ignore = [
165165
"D401", # do not always require imperative mood in first line
166166
"FBT001", "FBT002", "FBT003", # allow boolean parameters
167167
"ISC001", # allow string literal concatenation for auto-formatting
168+
"PLC0415", # allow run-time imports to avoid circular dependencies
168169
"PGH003", # type ignores do not need to be specific
169170
"PLR2004", # allow some "magic" values
170171
"PYI034", # do not check return value of new method

src/graphql/execution/incremental_publisher.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FormattedPendingResult(TypedDict, total=False):
6464
label: str
6565

6666

67-
class PendingResult:
67+
class PendingResult: # noqa: PLW1641
6868
"""Pending execution result"""
6969

7070
id: str
@@ -127,7 +127,7 @@ class FormattedCompletedResult(TypedDict, total=False):
127127
errors: list[GraphQLFormattedError]
128128

129129

130-
class CompletedResult:
130+
class CompletedResult: # noqa: PLW1641
131131
"""Completed execution result"""
132132

133133
id: str
@@ -192,7 +192,7 @@ class FormattedExecutionResult(TypedDict, total=False):
192192
extensions: dict[str, Any]
193193

194194

195-
class ExecutionResult:
195+
class ExecutionResult: # noqa: PLW1641
196196
"""The result of GraphQL execution.
197197
198198
- ``data`` is the result of a successful execution of the query.
@@ -267,7 +267,7 @@ class FormattedInitialIncrementalExecutionResult(TypedDict, total=False):
267267
extensions: dict[str, Any]
268268

269269

270-
class InitialIncrementalExecutionResult:
270+
class InitialIncrementalExecutionResult: # noqa: PLW1641
271271
"""Initial incremental execution result."""
272272

273273
data: dict[str, Any] | None
@@ -369,7 +369,7 @@ class FormattedIncrementalDeferResult(TypedDict, total=False):
369369
extensions: dict[str, Any]
370370

371371

372-
class IncrementalDeferResult:
372+
class IncrementalDeferResult: # noqa: PLW1641
373373
"""Incremental deferred execution result"""
374374

375375
data: dict[str, Any]
@@ -461,7 +461,7 @@ class FormattedIncrementalStreamResult(TypedDict, total=False):
461461
extensions: dict[str, Any]
462462

463463

464-
class IncrementalStreamResult:
464+
class IncrementalStreamResult: # noqa: PLW1641
465465
"""Incremental streamed execution result"""
466466

467467
items: list[Any]
@@ -560,7 +560,7 @@ class FormattedSubsequentIncrementalExecutionResult(TypedDict, total=False):
560560
extensions: dict[str, Any]
561561

562562

563-
class SubsequentIncrementalExecutionResult:
563+
class SubsequentIncrementalExecutionResult: # noqa: PLW1641
564564
"""Subsequent incremental execution result."""
565565

566566
__slots__ = "completed", "extensions", "has_next", "incremental", "pending"

src/graphql/language/location.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __eq__(self, other: object) -> bool:
4141
def __ne__(self, other: object) -> bool:
4242
return not self == other
4343

44+
def __hash__(self) -> int:
45+
return hash((self.line, self.column))
46+
4447

4548
def get_location(source: Source, position: int) -> SourceLocation:
4649
"""Get the line and column for a character position in the source.

src/graphql/language/source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def __eq__(self, other: object) -> bool:
7272
def __ne__(self, other: object) -> bool:
7373
return not self == other
7474

75+
def __hash__(self) -> int:
76+
return hash(self.body)
77+
7578

7679
def is_source(source: Any) -> TypeGuard[Source]:
7780
"""Test if the given value is a Source object.

src/graphql/pyutils/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def trunc_list(s: list) -> list:
171171
if len(s) > max_list_size:
172172
i = max_list_size // 2
173173
j = i - 1
174-
s = s[:i] + [ELLIPSIS] + s[-j:]
174+
s = [*s[:i], ELLIPSIS, *s[-j:]]
175175
return s
176176

177177

src/graphql/type/definition.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ class GraphQLFieldKwargs(TypedDict, total=False):
479479
ast_node: FieldDefinitionNode | None
480480

481481

482-
class GraphQLField:
482+
class GraphQLField: # noqa: PLW1641
483483
"""Definition of a GraphQL field"""
484484

485485
type: GraphQLOutputType
@@ -644,7 +644,7 @@ class GraphQLArgumentKwargs(TypedDict, total=False):
644644
ast_node: InputValueDefinitionNode | None
645645

646646

647-
class GraphQLArgument:
647+
class GraphQLArgument: # noqa: PLW1641
648648
"""Definition of a GraphQL argument"""
649649

650650
type: GraphQLInputType
@@ -1219,7 +1219,7 @@ class GraphQLEnumValueKwargs(TypedDict, total=False):
12191219
ast_node: EnumValueDefinitionNode | None
12201220

12211221

1222-
class GraphQLEnumValue:
1222+
class GraphQLEnumValue: # noqa: PLW1641
12231223
"""A GraphQL enum value."""
12241224

12251225
value: Any
@@ -1394,7 +1394,7 @@ class GraphQLInputFieldKwargs(TypedDict, total=False):
13941394
ast_node: InputValueDefinitionNode | None
13951395

13961396

1397-
class GraphQLInputField:
1397+
class GraphQLInputField: # noqa: PLW1641
13981398
"""Definition of a GraphQL input field"""
13991399

14001400
type: GraphQLInputType

src/graphql/type/directives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GraphQLDirectiveKwargs(TypedDict, total=False):
4949
ast_node: ast.DirectiveDefinitionNode | None
5050

5151

52-
class GraphQLDirective:
52+
class GraphQLDirective: # noqa: PLW1641
5353
"""GraphQL Directive
5454
5555
Directives are used by the GraphQL runtime as a way of modifying execution behavior.

src/graphql/utilities/ast_to_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def ast_to_dict(
4848
res.update(
4949
{
5050
key: ast_to_dict(getattr(node, key), locations, cache)
51-
for key in ("kind",) + node.keys[1:]
51+
for key in ("kind", *node.keys[1:])
5252
}
5353
)
5454
if locations:

tests/execution/test_defer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def can_compare_pending_result():
214214
assert result == tuple(args.values())
215215
assert result == tuple(args.values())[:2]
216216
assert result != tuple(args.values())[:1]
217-
assert result != tuple(args.values())[:1] + (["bar", 2],)
217+
assert result != (*tuple(args.values())[:1], ["bar", 2])
218218
assert result == args
219219
assert result != {**args, "id": "bar"}
220220
assert result != {**args, "path": ["bar", 2]}
@@ -239,7 +239,7 @@ def can_compare_completed_result():
239239
)
240240
assert result == tuple(args.values())
241241
assert result != tuple(args.values())[:1]
242-
assert result != tuple(args.values())[:1] + ([GraphQLError("oops")],)
242+
assert result != (*tuple(args.values())[:1], [GraphQLError("oops")])
243243
assert result == args
244244
assert result != {**args, "id": "bar"}
245245
assert result != {**args, "errors": [{"message": "oops"}]}

tests/language/test_location.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ def can_compare_with_formatted_location():
4141
different_location = SourceLocation(2, 2).formatted
4242
assert not location == different_location # noqa: SIM201
4343
assert location != different_location
44+
45+
def can_be_hashed():
46+
location = SourceLocation(1, 2)
47+
same_location = SourceLocation(1, 2)
48+
assert hash(location) == hash(same_location)
49+
different_location = SourceLocation(2, 2)
50+
assert hash(location) != hash(different_location)

tests/language/test_source.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def can_be_compared():
6969
assert not source == "bar" # noqa: SIM201
7070
assert source != "bar"
7171

72+
def can_be_hashed():
73+
source = Source("foo")
74+
same_source = Source("foo")
75+
assert hash(source) == hash(same_source)
76+
different_source = Source("bar")
77+
assert hash(source) != hash(different_source)
78+
7279
def can_create_weak_reference():
7380
source = Source("foo")
7481
ref = weakref.ref(source)

tests/pyutils/test_ref_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def can_create_a_map_with_scalar_keys_and_values():
2828
assert list(m.items()) == [("a", 1), ("b", 2), ("c", 3)]
2929
for k, v in m.items():
3030
assert k in m
31-
assert m[k] == v
31+
assert m[k] == v # noqa: PLR1733
3232
assert m.get(k) == v
3333
assert v not in m
3434
with pytest.raises(KeyError):
@@ -65,7 +65,7 @@ def can_create_a_map_with_three_objects_as_keys():
6565
assert list(m.items()) == [(obj1, 1), (obj2, 2), (obj3, 3)]
6666
for k, v in m.items():
6767
assert k in m
68-
assert m[k] == v
68+
assert m[k] == v # noqa: PLR1733
6969
assert m.get(k) == v
7070
assert v not in m
7171
with pytest.raises(KeyError):

tests/utilities/test_coerce_input_value.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from math import nan
3+
from math import isnan, nan
44
from typing import Any, NamedTuple
55

66
import pytest
@@ -91,7 +91,7 @@ def returns_no_error_for_null_result():
9191

9292
def returns_no_error_for_nan_result():
9393
result = _coerce_value({"value": nan}, TestScalar)
94-
assert expect_value(result) is nan
94+
assert isnan(expect_value(result))
9595

9696
def returns_an_error_for_undefined_result():
9797
result = _coerce_value({"value": Undefined}, TestScalar)
@@ -371,7 +371,7 @@ def returns_nan_as_value():
371371
result = _coerce_value({}, _get_test_input_object(nan))
372372
result_value = expect_value(result)
373373
assert "foo" in result_value
374-
assert result_value["foo"] is nan
374+
assert isnan(result_value["foo"])
375375

376376
def describe_for_graphql_list():
377377
TestList = GraphQLList(GraphQLInt)

tests/utilities/test_value_from_ast_untyped.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from math import nan
3+
from math import isnan, nan
44
from typing import Any
55

66
from graphql.language import FloatValueNode, IntValueNode, parse_value
@@ -14,8 +14,8 @@ def _compare_value(value: Any, expected: Any):
1414
assert value is None
1515
elif expected is Undefined:
1616
assert value is Undefined
17-
elif expected is nan:
18-
assert value is nan
17+
elif isinstance(expected, float) and isnan(expected):
18+
assert isnan(value)
1919
else:
2020
assert value == expected
2121

@@ -65,7 +65,7 @@ def parses_variables():
6565
_expect_value_from_vars("$testVariable", None, Undefined)
6666

6767
def parse_invalid_int_as_nan():
68-
assert value_from_ast_untyped(IntValueNode(value="invalid")) is nan
68+
assert isnan(value_from_ast_untyped(IntValueNode(value="invalid")))
6969

7070
def parse_invalid_float_as_nan():
71-
assert value_from_ast_untyped(FloatValueNode(value="invalid")) is nan
71+
assert isnan(value_from_ast_untyped(FloatValueNode(value="invalid")))

0 commit comments

Comments
 (0)