Skip to content

Commit 2e5944e

Browse files
committed
format code
1 parent 2c66e49 commit 2e5944e

File tree

9 files changed

+33
-97
lines changed

9 files changed

+33
-97
lines changed

graphene/pyutils/dataclasses.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,11 @@ def _field_init(f, frozen, globals, self_name):
442442
# This field does not need initialization. Signify that
443443
# to the caller by returning None.
444444
return None
445-
446445
# Only test this now, so that we can create variables for the
447446
# default. However, return None to signify that we're not going
448447
# to actually do the assignment statement for InitVars.
449448
if f._field_type == _FIELD_INITVAR:
450449
return None
451-
452450
# Now, actually generate the field assignment.
453451
return _field_assign(frozen, f.name, value, self_name)
454452

@@ -490,7 +488,6 @@ def _init_fn(fields, frozen, has_post_init, self_name):
490488
raise TypeError(
491489
f"non-default argument {f.name!r} " "follows default argument"
492490
)
493-
494491
globals = {"MISSING": MISSING, "_HAS_DEFAULT_FACTORY": _HAS_DEFAULT_FACTORY}
495492

496493
body_lines = []
@@ -500,16 +497,13 @@ def _init_fn(fields, frozen, has_post_init, self_name):
500497
# initialization (it's a pseudo-field). Just skip it.
501498
if line:
502499
body_lines.append(line)
503-
504500
# Does this class have a post-init function?
505501
if has_post_init:
506502
params_str = ",".join(f.name for f in fields if f._field_type is _FIELD_INITVAR)
507503
body_lines.append(f"{self_name}.{_POST_INIT_NAME}({params_str})")
508-
509504
# If no body lines, use 'pass'.
510505
if not body_lines:
511506
body_lines = ["pass"]
512-
513507
locals = {f"_type_{f.name}": f.type for f in fields}
514508
return _create_fn(
515509
"__init__",
@@ -674,7 +668,6 @@ def _get_field(cls, a_name, a_type):
674668
# This is a field in __slots__, so it has no default value.
675669
default = MISSING
676670
f = field(default=default)
677-
678671
# Only at this point do we know the name and the type. Set them.
679672
f.name = a_name
680673
f.type = a_type
@@ -705,7 +698,6 @@ def _get_field(cls, a_name, a_type):
705698
and _is_type(f.type, cls, typing, typing.ClassVar, _is_classvar)
706699
):
707700
f._field_type = _FIELD_CLASSVAR
708-
709701
# If the type is InitVar, or if it's a matching string annotation,
710702
# then it's an InitVar.
711703
if f._field_type is _FIELD:
@@ -717,7 +709,6 @@ def _get_field(cls, a_name, a_type):
717709
and _is_type(f.type, cls, dataclasses, dataclasses.InitVar, _is_initvar)
718710
):
719711
f._field_type = _FIELD_INITVAR
720-
721712
# Validations for individual fields. This is delayed until now,
722713
# instead of in the Field() constructor, since only here do we
723714
# know the field name, which allows for better error reporting.
@@ -731,14 +722,12 @@ def _get_field(cls, a_name, a_type):
731722
# example, how about init=False (or really,
732723
# init=<not-the-default-init-value>)? It makes no sense for
733724
# ClassVar and InitVar to specify init=<anything>.
734-
735725
# For real fields, disallow mutable defaults for known types.
736726
if f._field_type is _FIELD and isinstance(f.default, (list, dict, set)):
737727
raise ValueError(
738728
f"mutable default {type(f.default)} for field "
739729
f"{f.name} is not allowed: use default_factory"
740730
)
741-
742731
return f
743732

744733

@@ -827,7 +816,6 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
827816
fields[f.name] = f
828817
if getattr(b, _PARAMS).frozen:
829818
any_frozen_base = True
830-
831819
# Annotations that are defined in this class (not in base
832820
# classes). If __annotations__ isn't present, then this class
833821
# adds no new annotations. We use this to compute fields that are
@@ -866,22 +854,18 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
866854
delattr(cls, f.name)
867855
else:
868856
setattr(cls, f.name, f.default)
869-
870857
# Do we have any Field members that don't also have annotations?
871858
for name, value in cls.__dict__.items():
872859
if isinstance(value, Field) and not name in cls_annotations:
873860
raise TypeError(f"{name!r} is a field but has no type annotation")
874-
875861
# Check rules that apply if we are derived from any dataclasses.
876862
if has_dataclass_bases:
877863
# Raise an exception if any of our bases are frozen, but we're not.
878864
if any_frozen_base and not frozen:
879865
raise TypeError("cannot inherit non-frozen dataclass from a " "frozen one")
880-
881866
# Raise an exception if we're frozen, but none of our bases are.
882867
if not any_frozen_base and frozen:
883868
raise TypeError("cannot inherit frozen dataclass from a " "non-frozen one")
884-
885869
# Remember all of the fields on our class (including bases). This
886870
# also marks this class as being a dataclass.
887871
setattr(cls, _FIELDS, fields)
@@ -900,7 +884,6 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
900884
# eq methods.
901885
if order and not eq:
902886
raise ValueError("eq must be true if order is true")
903-
904887
if init:
905888
# Does this class have a post-init function?
906889
has_post_init = hasattr(cls, _POST_INIT_NAME)
@@ -920,15 +903,13 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
920903
"__dataclass_self__" if "self" in fields else "self",
921904
),
922905
)
923-
924906
# Get the fields as a list, and include only real fields. This is
925907
# used in all of the following methods.
926908
field_list = [f for f in fields.values() if f._field_type is _FIELD]
927909

928910
if repr:
929911
flds = [f for f in field_list if f.repr]
930912
_set_new_attribute(cls, "__repr__", _repr_fn(flds))
931-
932913
if eq:
933914
# Create _eq__ method. There's no need for a __ne__ method,
934915
# since python will call __eq__ and negate it.
@@ -938,7 +919,6 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
938919
_set_new_attribute(
939920
cls, "__eq__", _cmp_fn("__eq__", "==", self_tuple, other_tuple)
940921
)
941-
942922
if order:
943923
# Create and set the ordering methods.
944924
flds = [f for f in field_list if f.compare]
@@ -958,15 +938,13 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
958938
f"in class {cls.__name__}. Consider using "
959939
"functools.total_ordering"
960940
)
961-
962941
if frozen:
963942
for fn in _frozen_get_del_attr(cls, field_list):
964943
if _set_new_attribute(cls, fn.__name__, fn):
965944
raise TypeError(
966945
f"Cannot overwrite attribute {fn.__name__} "
967946
f"in class {cls.__name__}"
968947
)
969-
970948
# Decide if/how we're going to create a hash function.
971949
hash_action = _hash_action[
972950
bool(unsafe_hash), bool(eq), bool(frozen), has_explicit_hash
@@ -975,11 +953,9 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
975953
# No need to call _set_new_attribute here, since by the time
976954
# we're here the overwriting is unconditional.
977955
cls.__hash__ = hash_action(cls, field_list)
978-
979956
if not getattr(cls, "__doc__"):
980957
# Create a class doc-string.
981958
cls.__doc__ = cls.__name__ + str(inspect.signature(cls)).replace(" -> None", "")
982-
983959
return cls
984960

985961

@@ -1015,7 +991,6 @@ def wrap(cls):
1015991
if _cls is None:
1016992
# We're called with parens.
1017993
return wrap
1018-
1019994
# We're called as @dataclass without parens.
1020995
return wrap(_cls)
1021996

@@ -1032,7 +1007,6 @@ def fields(class_or_instance):
10321007
fields = getattr(class_or_instance, _FIELDS)
10331008
except AttributeError:
10341009
raise TypeError("must be called with a dataclass type or instance")
1035-
10361010
# Exclude pseudo-fields. Note that fields is sorted by insertion
10371011
# order, so the order of the tuple is as the fields were defined.
10381012
return tuple(f for f in fields.values() if f._field_type is _FIELD)
@@ -1174,7 +1148,6 @@ class C(Base):
11741148
else:
11751149
# Copy namespace since we're going to mutate it.
11761150
namespace = namespace.copy()
1177-
11781151
# While we're looking through the field names, validate that they
11791152
# are identifiers, are not keywords, and not duplicates.
11801153
seen = set()
@@ -1184,23 +1157,23 @@ class C(Base):
11841157
name = item
11851158
tp = "typing.Any"
11861159
elif len(item) == 2:
1187-
name, tp, = item
1160+
(
1161+
name,
1162+
tp,
1163+
) = item
11881164
elif len(item) == 3:
11891165
name, tp, spec = item
11901166
namespace[name] = spec
11911167
else:
11921168
raise TypeError(f"Invalid field: {item!r}")
1193-
11941169
if not isinstance(name, str) or not name.isidentifier():
11951170
raise TypeError(f"Field names must be valid identifers: {name!r}")
11961171
if keyword.iskeyword(name):
11971172
raise TypeError(f"Field names must not be keywords: {name!r}")
11981173
if name in seen:
11991174
raise TypeError(f"Field name duplicated: {name!r}")
1200-
12011175
seen.add(name)
12021176
anns[name] = tp
1203-
12041177
namespace["__annotations__"] = anns
12051178
# We use `types.new_class()` instead of simply `type()` to allow dynamic creation
12061179
# of generic dataclassses.
@@ -1229,14 +1202,13 @@ class C:
12291202
c = C(1, 2)
12301203
c1 = replace(c, x=3)
12311204
assert c1.x == 3 and c1.y == 2
1232-
"""
1205+
"""
12331206

12341207
# We're going to mutate 'changes', but that's okay because it's a
12351208
# new dict, even if called with 'replace(obj, **my_changes)'.
12361209

12371210
if not _is_dataclass_instance(obj):
12381211
raise TypeError("replace() should be called on dataclass instances")
1239-
12401212
# It's an error to have init=False fields in 'changes'.
12411213
# If a field is not in 'changes', read its value from the provided obj.
12421214

@@ -1250,10 +1222,8 @@ class C:
12501222
"replace()"
12511223
)
12521224
continue
1253-
12541225
if f.name not in changes:
12551226
changes[f.name] = getattr(obj, f.name)
1256-
12571227
# Create the new object, which calls __init__() and
12581228
# __post_init__() (if defined), using all of the init fields we've
12591229
# added and/or left in 'changes'. If there are values supplied in

graphene/relay/tests/test_connection_query.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def cursor_for(ltr):
6666
async def execute(args=""):
6767
if args:
6868
args = "(" + args + ")"
69-
7069
return await schema.execute_async(
7170
"""
7271
{
@@ -164,14 +163,16 @@ async def test_respects_first_and_after_and_before_too_few():
164163
@mark.asyncio
165164
async def test_respects_first_and_after_and_before_too_many():
166165
await check(
167-
f'first: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
166+
f'first: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
167+
"BCD",
168168
)
169169

170170

171171
@mark.asyncio
172172
async def test_respects_first_and_after_and_before_exactly_right():
173173
await check(
174-
f'first: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
174+
f'first: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
175+
"BCD",
175176
)
176177

177178

@@ -187,14 +188,16 @@ async def test_respects_last_and_after_and_before_too_few():
187188
@mark.asyncio
188189
async def test_respects_last_and_after_and_before_too_many():
189190
await check(
190-
f'last: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
191+
f'last: 4, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
192+
"BCD",
191193
)
192194

193195

194196
@mark.asyncio
195197
async def test_respects_last_and_after_and_before_exactly_right():
196198
await check(
197-
f'last: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"', "BCD",
199+
f'last: 3, after: "{cursor_for("A")}", before: "{cursor_for("E")}"',
200+
"BCD",
198201
)
199202

200203

graphene/types/mutation.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def __init_subclass_with_meta__(
7676
):
7777
if not _meta:
7878
_meta = MutationOptions(cls)
79-
8079
output = output or getattr(cls, "Output", None)
8180
fields = {}
8281

@@ -85,14 +84,12 @@ def __init_subclass_with_meta__(
8584
interface, Interface
8685
), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
8786
fields.update(interface._meta.fields)
88-
8987
if not output:
9088
# If output is defined, we don't need to get the fields
9189
fields = {}
9290
for base in reversed(cls.__mro__):
9391
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
9492
output = cls
95-
9693
if not arguments:
9794
input_class = getattr(cls, "Arguments", None)
9895
if not input_class:
@@ -106,22 +103,18 @@ def __init_subclass_with_meta__(
106103
" https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#mutation-input"
107104
)
108105
)
109-
110106
if input_class:
111107
arguments = props(input_class)
112108
else:
113109
arguments = {}
114-
115110
if not resolver:
116111
mutate = getattr(cls, "mutate", None)
117112
assert mutate, "All mutations must define a mutate method in it"
118113
resolver = get_unbound_function(mutate)
119-
120114
if _meta.fields:
121115
_meta.fields.update(fields)
122116
else:
123117
_meta.fields = fields
124-
125118
_meta.interfaces = interfaces
126119
_meta.output = output
127120
_meta.resolver = resolver
@@ -133,7 +126,7 @@ def __init_subclass_with_meta__(
133126
def Field(
134127
cls, name=None, description=None, deprecation_reason=None, required=False
135128
):
136-
""" Mount instance of mutation Field. """
129+
"""Mount instance of mutation Field."""
137130
return Field(
138131
cls._meta.output,
139132
args=cls._meta.arguments,

graphene/types/objecttype.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from dataclasses import make_dataclass, field
88
except ImportError:
99
from ..pyutils.dataclasses import make_dataclass, field # type: ignore
10-
1110
# For static type checking with Mypy
1211
MYPY = False
1312
if MYPY:
@@ -28,7 +27,11 @@ class InterObjectType:
2827
pass
2928

3029
base_cls = super().__new__(
31-
cls, name_, (InterObjectType,) + bases, namespace, **options,
30+
cls,
31+
name_,
32+
(InterObjectType,) + bases,
33+
namespace,
34+
**options,
3235
)
3336
if base_cls._meta:
3437
fields = [
@@ -133,18 +136,15 @@ def __init_subclass_with_meta__(
133136
):
134137
if not _meta:
135138
_meta = ObjectTypeOptions(cls)
136-
137139
fields = {}
138140

139141
for interface in interfaces:
140142
assert issubclass(
141143
interface, Interface
142144
), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
143145
fields.update(interface._meta.fields)
144-
145146
for base in reversed(cls.__mro__):
146147
fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))
147-
148148
assert not (possible_types and cls.is_type_of), (
149149
f"{cls.__name__}.Meta.possible_types will cause type collision with {cls.__name__}.is_type_of. "
150150
"Please use one or other."
@@ -154,7 +154,6 @@ def __init_subclass_with_meta__(
154154
_meta.fields.update(fields)
155155
else:
156156
_meta.fields = fields
157-
158157
if not _meta.interfaces:
159158
_meta.interfaces = interfaces
160159
_meta.possible_types = possible_types

0 commit comments

Comments
 (0)