Skip to content

Commit e399b18

Browse files
committed
Use __slots__ in even more places.
1 parent 53e6bc8 commit e399b18

File tree

9 files changed

+27
-10
lines changed

9 files changed

+27
-10
lines changed

graphql/core/error.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class Error(Exception):
66

77

88
class GraphQLError(Error):
9+
__slots__ = 'message', 'nodes', 'stack', '_source', '_positions'
10+
911
def __init__(self, message, nodes=None, stack=None, source=None, positions=None):
1012
super(GraphQLError, self).__init__(message)
1113
self.message = message
@@ -43,5 +45,5 @@ def format_error(error):
4345
'locations': [
4446
{'line': loc.line, 'column': loc.column}
4547
for loc in error.locations
46-
],
48+
],
4749
}

graphql/core/execution/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class ExecutionContext(object):
2727
Namely, schema of the type system that is currently executing,
2828
and the fragments defined in the query document"""
2929

30+
__slots__ = 'schema', 'fragments', 'root', 'operation', 'variables', 'errors', 'request_context'
31+
3032
def __init__(self, schema, root, document_ast, operation_name, args, request_context):
3133
"""Constructs a ExecutionContext object from the arguments passed
3234
to execute, which we will pass throughout the other execution
@@ -75,13 +77,15 @@ class ExecutionResult(object):
7577
query, `errors` is null if no errors occurred, and is a
7678
non-empty array if an error occurred."""
7779

80+
__slots__ = 'data', 'errors', 'invalid'
81+
7882
def __init__(self, data=None, errors=None, invalid=False):
7983
self.data = data
8084
if errors:
8185
errors = [
8286
error.value if isinstance(error, DeferredException) else error
8387
for error in errors
84-
]
88+
]
8589

8690
self.errors = errors
8791

graphql/core/language/ast.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44

55
class Node(object):
6-
pass
6+
__slots__ = ()
77

88

99
class Definition(Node):
10-
pass
10+
__slots__ = ()
1111

1212

1313
class Document(Node):
@@ -163,7 +163,7 @@ def __hash__(self):
163163

164164

165165
class Selection(Node):
166-
pass
166+
__slots__ = ()
167167

168168

169169
class Field(Selection):
@@ -371,7 +371,7 @@ def __hash__(self):
371371

372372

373373
class Value(Node):
374-
pass
374+
__slots__ = ()
375375

376376

377377
class Variable(Value):
@@ -703,7 +703,7 @@ def __hash__(self):
703703

704704

705705
class Type(Node):
706-
pass
706+
__slots__ = ()
707707

708708

709709
class NamedType(Type):
@@ -835,7 +835,7 @@ def __hash__(self):
835835

836836

837837
class TypeDefinition(Node):
838-
pass
838+
__slots__ = ()
839839

840840

841841
class ObjectTypeDefinition(TypeDefinition):

graphql/core/language/printer.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def print_ast(ast):
99

1010

1111
class PrintingVisitor(Visitor):
12+
__slots__ = ()
13+
1214
def leave_Name(self, node, *args):
1315
return node.value
1416

graphql/core/language/source.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
class Source(object):
5+
__slots__ = 'body', 'name'
6+
57
def __init__(self, body, name='GraphQL'):
68
self.body = body
79
self.name = name

graphql/core/pyutils/default_ordered_dict.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
class DefaultOrderedDict(OrderedDict):
5+
__slots__ = 'default_factory',
6+
57
# Source: http://stackoverflow.com/a/6190500/562769
68
def __init__(self, default_factory=None, *a, **kw):
79
if (default_factory is not None and

graphql/core/pyutils/defer.py

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class AlreadyCalledDeferred(Exception):
7373

7474
class DeferredException(object):
7575
"""Allows to defer exceptions."""
76+
__slots__ = 'type', 'value', 'traceback'
7677

7778
def __init__(self, type=None, value=None, traceback=None):
7879
"""Return a new DeferredException instance.
@@ -190,6 +191,8 @@ class Deferred(object):
190191
CALLBACK3 ERRBACK3
191192
"""
192193

194+
__slots__ = 'callbacks', 'errbacks', 'called', 'paused', '_running', 'result'
195+
193196
def __init__(self):
194197
"""Return a new Deferred instance."""
195198
self.callbacks = []

graphql/core/pyutils/pair_set.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class PairSet(object):
2+
__slots__ = '_data',
3+
24
def __init__(self):
35
self._data = set()
46

scripts/generate_ast.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def start_file(self):
3636
3737
3838
class Node(object):
39-
pass''')
39+
__slots__ = ()''')
4040

4141
def end_file(self):
4242
pass
@@ -131,7 +131,7 @@ def start_union(self, name):
131131
print('''
132132
133133
class {name}(Node):
134-
pass'''.format(name=name))
134+
__slots__ = ()'''.format(name=name))
135135

136136
def union_option(self, option):
137137
option = remap_type(option)

0 commit comments

Comments
 (0)