Skip to content

Commit 85635a2

Browse files
committed
Cosmetic changes, run black
1 parent faa80af commit 85635a2

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

src/graphql/execution/middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class MiddlewareManager:
2020
must be aware of this and check whether values are awaitable before awaiting them.
2121
"""
2222

23-
__slots__ = "__weakref__", "__dict__", "middlewares", "_middleware_resolvers", "_cached_resolvers"
23+
# allow custom attributes (not used internally)
24+
__slots__ = "__dict__", "middlewares", "_middleware_resolvers", "_cached_resolvers"
2425

2526
_cached_resolvers: Dict[GraphQLFieldResolver, GraphQLFieldResolver]
2627
_middleware_resolvers: Optional[List[Callable]]

src/graphql/language/ast.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Token:
7272
Represents a range of characters represented by a lexical token within a Source.
7373
"""
7474

75-
__slots__ = ("kind", "start", "end", "line", "column", "prev", "next", "value")
75+
__slots__ = "kind", "start", "end", "line", "column", "prev", "next", "value"
7676

7777
kind: TokenKind # the kind of token
7878
start: int # the character offset at which this Node begins
@@ -162,7 +162,13 @@ class Location:
162162
region of the source from which the AST derived.
163163
"""
164164

165-
__slots__ = ("start", "end", "start_token", "end_token", "source")
165+
__slots__ = (
166+
"start",
167+
"end",
168+
"start_token",
169+
"end_token",
170+
"source",
171+
)
166172

167173
start: int # character offset at which this Node begins
168174
end: int # character offset at which this Node ends
@@ -214,7 +220,8 @@ class OperationType(Enum):
214220
class Node:
215221
"""AST nodes"""
216222

217-
__slots__ = ("__dict__", "__weakref__", "loc",)
223+
# allow custom attributes and weak references (not used internally)
224+
__slots__ = "__dict__", "__weakref__", "loc"
218225

219226
loc: Optional[Location]
220227

src/graphql/language/source.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class Source:
77
"""A representation of source input to GraphQL."""
88

9+
# allow custom attributes and weak references (not used internally)
910
__slots__ = "__weakref__", "__dict__", "body", "name", "location_offset"
1011

1112
def __init__(

tests/language/test_ast.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ def can_hash():
187187
assert node3 != node
188188
assert hash(node3) != hash(node)
189189

190+
def can_create_weak_reference():
191+
node = SampleTestNode(alpha=1, beta=2)
192+
ref = weakref.ref(node)
193+
assert ref() is node
194+
195+
def can_create_custom_attribute():
196+
node = SampleTestNode(alpha=1, beta=2)
197+
node.gamma = 3 # type: ignore
198+
assert node.gamma == 3 # type: ignore
199+
190200
def can_create_shallow_copy():
191201
node = SampleTestNode(alpha=1, beta=2)
192202
node2 = copy(node)
@@ -225,13 +235,3 @@ class Foo(Node):
225235

226236
def provides_keys_as_class_attribute():
227237
assert SampleTestNode.keys == ["loc", "alpha", "beta"]
228-
229-
def can_weakref():
230-
node = SampleTestNode(alpha=1, beta=2)
231-
wr = weakref.ref(node) # That this works is 90% of the test
232-
assert wr() is node
233-
234-
def can_make_attrs():
235-
node = SampleTestNode(alpha=1, beta=2)
236-
node.__new_random_attr = "Hello!" # That this works is 90% of the test
237-
assert node.__new_random_attr == "Hello!"

tests/language/test_source.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import weakref
2+
13
from pytest import raises # type: ignore
24

35
from graphql.language import Source, SourceLocation
@@ -63,6 +65,16 @@ def can_be_compared():
6365
assert not source == "bar"
6466
assert source != "bar"
6567

68+
def can_create_weak_reference():
69+
source = Source("foo")
70+
ref = weakref.ref(source)
71+
assert ref() is source
72+
73+
def can_create_custom_attribute():
74+
node = Source("foo")
75+
node.custom = "bar" # type: ignore
76+
assert node.custom == "bar" # type: ignore
77+
6678
def rejects_invalid_body_and_name():
6779
with raises(TypeError, match="body must be a string\\."):
6880
# noinspection PyTypeChecker

0 commit comments

Comments
 (0)