Skip to content

Commit 8f426f7

Browse files
committed
Rename read_only_list/dict to frozen_list/dict
Since GraphQL.js now uses frozen objects instead of ReadOnlyArrays, this is a better analogy, and Python already has frozenset(). Replicates graphql/graphql-js@f55c2a3
1 parent b0dc730 commit 8f426f7

17 files changed

+184
-184
lines changed

docs/modules/pyutils.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ PyUtils
2020
.. autofunction:: or_list
2121
.. autofunction:: quoted_or_list
2222
.. autofunction:: suggestion_list
23-
.. autoclass:: ReadOnlyError
24-
.. autoclass:: ReadOnlyList
25-
.. autoclass:: ReadOnlyDict
23+
.. autoclass:: FrozenError
24+
.. autoclass:: FrozenList
25+
.. autoclass:: FrozenDict

docs/modules/validation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ rules in this list has been adjusted to lead to the most clear output when encou
2828
multiple validation errors:
2929

3030
.. autodata:: specified_rules
31-
:annotation: = ReadOnlyList([...])
31+
:annotation: = FrozenList([...])
3232

3333
Spec Section: "Executable Definitions"
3434

graphql/pyutils/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
from .or_list import or_list
2222
from .quoted_or_list import quoted_or_list
2323
from .suggestion_list import suggestion_list
24-
from .read_only_error import ReadOnlyError
25-
from .read_only_list import ReadOnlyList
26-
from .read_only_dict import ReadOnlyDict
24+
from .frozen_error import FrozenError
25+
from .frozen_list import FrozenList
26+
from .frozen_dict import FrozenDict
2727

2828
__all__ = [
2929
"camel_to_snake",
@@ -41,7 +41,7 @@
4141
"or_list",
4242
"quoted_or_list",
4343
"suggestion_list",
44-
"ReadOnlyError",
45-
"ReadOnlyList",
46-
"ReadOnlyDict",
44+
"FrozenError",
45+
"FrozenList",
46+
"FrozenDict",
4747
]
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
__all__ = ["ReadOnlyDict"]
1+
__all__ = ["FrozenDict"]
22

3-
from .read_only_error import ReadOnlyError
3+
from .frozen_error import FrozenError
44

55

6-
class ReadOnlyDict(dict):
6+
class FrozenDict(dict):
77
"""Dictionary that can only be read, but not changed."""
88

99
def __delitem__(self, key):
10-
raise ReadOnlyError
10+
raise FrozenError
1111

1212
def __setitem__(self, key, value):
13-
raise ReadOnlyError
13+
raise FrozenError
1414

1515
def __add__(self, value):
1616
return dict.__add__(self, value)
1717

1818
def __iadd__(self, value):
19-
raise ReadOnlyError
19+
raise FrozenError
2020

2121
def clear(self):
22-
raise ReadOnlyError
22+
raise FrozenError
2323

2424
def pop(self, key, default=None):
25-
raise ReadOnlyError
25+
raise FrozenError
2626

2727
def popitem(self):
28-
raise ReadOnlyError
28+
raise FrozenError
2929

3030
def setdefault(self, key, default=None):
31-
raise ReadOnlyError
31+
raise FrozenError
3232

3333
def update(self, other=None):
34-
raise ReadOnlyError
34+
raise FrozenError

graphql/pyutils/frozen_error.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__all__ = ["FrozenError"]
2+
3+
4+
class FrozenError(TypeError):
5+
"""Error when trying to change a frozen (read only) collection."""
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
1-
__all__ = ["ReadOnlyList"]
1+
__all__ = ["FrozenList"]
22

3-
from .read_only_error import ReadOnlyError
3+
from .frozen_error import FrozenError
44

55

6-
class ReadOnlyList(list):
6+
class FrozenList(list):
77
"""List that can only be read, but not changed."""
88

99
def __delitem__(self, key):
10-
raise ReadOnlyError
10+
raise FrozenError
1111

1212
def __setitem__(self, key, value):
13-
raise ReadOnlyError
13+
raise FrozenError
1414

1515
def __add__(self, value):
1616
if isinstance(value, tuple):
1717
value = list(value)
1818
return list.__add__(self, value)
1919

2020
def __iadd__(self, value):
21-
raise ReadOnlyError
21+
raise FrozenError
2222

2323
def __mul__(self, value):
2424
return list.__mul__(self, value)
2525

2626
def __imul__(self, value):
27-
raise ReadOnlyError
27+
raise FrozenError
2828

2929
def append(self, x):
30-
raise ReadOnlyError
30+
raise FrozenError
3131

3232
def extend(self, iterable):
33-
raise ReadOnlyError
33+
raise FrozenError
3434

3535
def insert(self, i, x):
36-
raise ReadOnlyError
36+
raise FrozenError
3737

3838
def remove(self, x):
39-
raise ReadOnlyError
39+
raise FrozenError
4040

4141
def pop(self, i=None):
42-
raise ReadOnlyError
42+
raise FrozenError
4343

4444
def clear(self):
45-
raise ReadOnlyError
45+
raise FrozenError
4646

4747
def sort(self, *, key=None, reverse=False):
48-
raise ReadOnlyError
48+
raise FrozenError
4949

5050
def reverse(self):
51-
raise ReadOnlyError
51+
raise FrozenError

graphql/pyutils/read_only_error.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

graphql/type/directives.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, Dict, Sequence, cast
22

33
from ..language import ast, DirectiveLocation
4-
from ..pyutils import inspect, ReadOnlyList
4+
from ..pyutils import inspect, FrozenList
55
from .definition import GraphQLArgument, GraphQLInputType, GraphQLNonNull, is_input_type
66
from .scalars import GraphQLBoolean, GraphQLString
77

@@ -165,7 +165,7 @@ def assert_directive(directive: Any) -> GraphQLDirective:
165165
)
166166

167167

168-
specified_directives = ReadOnlyList(
168+
specified_directives = FrozenList(
169169
[GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective]
170170
)
171171
specified_directives.__doc__ = """The full list of specified directives."""

graphql/type/introspection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
is_union_type,
2222
)
2323
from ..language import DirectiveLocation, print_ast
24-
from ..pyutils import inspect, ReadOnlyDict
24+
from ..pyutils import inspect, FrozenDict
2525
from .scalars import GraphQLBoolean, GraphQLString
2626

2727
__all__ = [
@@ -492,7 +492,7 @@ class TypeKind(Enum):
492492

493493
# Since double underscore names are subject to name mangling in Python,
494494
# the introspection classes are best imported via this dictionary:
495-
introspection_types = ReadOnlyDict(
495+
introspection_types = FrozenDict(
496496
{
497497
"__Schema": __Schema,
498498
"__Directive": __Directive,

graphql/type/scalars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any
33

44
from ..error import INVALID
5-
from ..pyutils import inspect, is_finite, is_integer, ReadOnlyDict
5+
from ..pyutils import inspect, is_finite, is_integer, FrozenDict
66
from ..language.ast import (
77
BooleanValueNode,
88
FloatValueNode,
@@ -241,7 +241,7 @@ def parse_id_literal(ast, _variables=None):
241241
)
242242

243243

244-
specified_scalar_types = ReadOnlyDict(
244+
specified_scalar_types = FrozenDict(
245245
{
246246
type_.name: type_
247247
for type_ in (

0 commit comments

Comments
 (0)