Skip to content

Commit 7ecb4e6

Browse files
authored
Merge pull request #1387 from GDGSNF/master
Chore: Refactor Multi Expression Code ✨
2 parents 9311d35 + 7108bc8 commit 7ecb4e6

File tree

8 files changed

+20
-37
lines changed

8 files changed

+20
-37
lines changed

graphene/pyutils/version.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ def get_version(version=None):
1919
sub = ""
2020
if version[3] == "alpha" and version[4] == 0:
2121
git_changeset = get_git_changeset()
22-
if git_changeset:
23-
sub = ".dev%s" % git_changeset
24-
else:
25-
sub = ".dev"
22+
sub = ".dev%s" % git_changeset if git_changeset else ".dev"
2623
elif version[3] != "final":
2724
mapping = {"alpha": "a", "beta": "b", "rc": "rc"}
2825
sub = mapping[version[3]] + str(version[4])

graphene/relay/node.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ def is_node(objecttype):
1818
if not issubclass(objecttype, ObjectType):
1919
return False
2020

21-
for i in objecttype._meta.interfaces:
22-
if issubclass(i, Node):
23-
return True
24-
25-
return False
21+
return any(issubclass(i, Node) for i in objecttype._meta.interfaces)
2622

2723

2824
class GlobalID(Field):
@@ -94,7 +90,7 @@ def get_node_from_global_id(cls, info, global_id, only_type=None):
9490
raise Exception(
9591
f'Unable to parse global ID "{global_id}". '
9692
'Make sure it is a base64 encoded string in the format: "TypeName:id". '
97-
f"Exception message: {str(e)}"
93+
f"Exception message: {e}"
9894
)
9995

10096
graphene_type = info.schema.get_type(_type)

graphene/types/mutation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ def __init_subclass_with_meta__(
101101
"Read more:"
102102
" https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#mutation-input"
103103
)
104-
if input_class:
105-
arguments = props(input_class)
106-
else:
107-
arguments = {}
104+
arguments = props(input_class) if input_class else {}
108105
if not resolver:
109106
mutate = getattr(cls, "mutate", None)
110107
assert mutate, "All mutations must define a mutate method in it"

graphene/types/resolver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ def dict_resolver(attname, default_value, root, info, **args):
77

88

99
def dict_or_attr_resolver(attname, default_value, root, info, **args):
10-
resolver = attr_resolver
11-
if isinstance(root, dict):
12-
resolver = dict_resolver
10+
resolver = dict_resolver if isinstance(root, dict) else attr_resolver
1311
return resolver(attname, default_value, root, info, **args)
1412

1513

graphene/types/tests/test_subscribe_async.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class Subscription(ObjectType):
1414
count_to_ten = Field(Int)
1515

1616
async def subscribe_count_to_ten(root, info):
17-
count = 0
18-
while count < 10:
19-
count += 1
17+
for count in range(1, 11):
2018
yield count
2119

2220

graphene/utils/module_loading.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@ def import_string(dotted_path, dotted_attributes=None):
2727

2828
if not dotted_attributes:
2929
return result
30-
else:
31-
attributes = dotted_attributes.split(".")
32-
traveled_attributes = []
33-
try:
34-
for attribute in attributes:
35-
traveled_attributes.append(attribute)
36-
result = getattr(result, attribute)
37-
return result
38-
except AttributeError:
39-
raise ImportError(
40-
'Module "%s" does not define a "%s" attribute inside attribute/class "%s"'
41-
% (module_path, ".".join(traveled_attributes), class_name)
42-
)
30+
attributes = dotted_attributes.split(".")
31+
traveled_attributes = []
32+
try:
33+
for attribute in attributes:
34+
traveled_attributes.append(attribute)
35+
result = getattr(result, attribute)
36+
return result
37+
except AttributeError:
38+
raise ImportError(
39+
'Module "%s" does not define a "%s" attribute inside attribute/class "%s"'
40+
% (module_path, ".".join(traveled_attributes), class_name)
41+
)
4342

4443

4544
def lazy_import(dotted_path, dotted_attributes=None):

graphene/utils/tests/test_orderedtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def test_orderedtype_non_orderabletypes():
3838

3939
assert one.__lt__(1) == NotImplemented
4040
assert one.__gt__(1) == NotImplemented
41-
assert not one == 1
41+
assert one != 1

graphene/validation/tests/test_disable_introspection.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ def resolve_name(root, info):
1818
def run_query(query: str):
1919
document = parse(query)
2020

21-
errors = validate(
21+
return validate(
2222
schema=schema.graphql_schema,
2323
document_ast=document,
2424
rules=(DisableIntrospection,),
2525
)
2626

27-
return errors
28-
2927

3028
def test_disallows_introspection_queries():
3129
errors = run_query("{ __schema { queryType { name } } }")

0 commit comments

Comments
 (0)