Skip to content

Commit dd09704

Browse files
committed
More f-strings.
1 parent b6017bd commit dd09704

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

UPGRADE-v2.0.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,7 @@ class Base(ObjectType):
379379
id = ID()
380380

381381
def resolve_id(self, info):
382-
return "{type}_{id}".format(
383-
type=self.__class__.__name__,
384-
id=self.id
385-
)
382+
return f"{self.__class__.__name__}_{self.id}"
386383
```
387384

388385
### UUID Scalar

docs/relay/nodes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Example of a custom node:
5252
5353
@staticmethod
5454
def to_global_id(type, id):
55-
return '{}:{}'.format(type, id)
55+
return f'{type}:{id}'
5656
5757
@staticmethod
5858
def get_node_from_global_id(info, global_id, only_type=None):

docs/types/objecttypes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This example model defines a Person, with a first and a last name:
2626
full_name = graphene.String()
2727
2828
def resolve_full_name(root, info):
29-
return '{} {}'.format(root.first_name, root.last_name)
29+
return f'{root.first_name} {root.last_name}'
3030
3131
**first\_name** and **last\_name** are fields of the ObjectType. Each
3232
field is specified as a class attribute, and each attribute maps to a
@@ -173,7 +173,7 @@ A field can use a custom resolver from outside the class:
173173
import graphene
174174
175175
def resolve_full_name(person, info):
176-
return '{} {}'.format(person.first_name, person.last_name)
176+
return f'{person.first_name} {person.last_name}'
177177
178178
class Person(graphene.ObjectType):
179179
first_name = graphene.String()

graphene/pyutils/signature.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def signature(obj):
5454
"""Get a signature object for the passed callable."""
5555

5656
if not callable(obj):
57-
raise TypeError(f"{obj!r} is not a callable object")
57+
raise TypeError(f"{repr(obj)} is not a callable object")
5858

5959
if isinstance(obj, types.MethodType):
6060
sig = signature(obj.__func__)
@@ -101,7 +101,7 @@ def signature(obj):
101101
try:
102102
ba = sig.bind_partial(*partial_args, **partial_keywords)
103103
except TypeError as ex:
104-
msg = f"partial object {obj!r} has incorrect arguments"
104+
msg = f"partial object {repr(obj)} has incorrect arguments"
105105
raise ValueError(msg)
106106

107107
for arg_name, arg_value in ba.arguments.items():
@@ -171,10 +171,10 @@ def signature(obj):
171171

172172
if isinstance(obj, types.BuiltinFunctionType):
173173
# Raise a nicer error message for builtins
174-
msg = f"no signature found for builtin function {obj!r}"
174+
msg = f"no signature found for builtin function {repr(obj)}"
175175
raise ValueError(msg)
176176

177-
raise ValueError(f"callable {obj!r} is not supported by signature")
177+
raise ValueError(f"callable {repr(obj)} is not supported by signature")
178178

179179

180180
class _void(object):
@@ -195,7 +195,7 @@ def __str__(self):
195195
return self._name
196196

197197
def __repr__(self):
198-
return f"<_ParameterKind: {self._name!r}>"
198+
return f"<_ParameterKind: {repr(self._name)}>"
199199

200200

201201
_POSITIONAL_ONLY = _ParameterKind(0, name="POSITIONAL_ONLY")
@@ -263,7 +263,7 @@ def __init__(
263263
else:
264264
name = str(name)
265265
if kind != _POSITIONAL_ONLY and not re.match(r"[a-z_]\w*$", name, re.I):
266-
msg = f"{name!r} is not a valid parameter name"
266+
msg = f"{repr(name)} is not a valid parameter name"
267267
raise ValueError(msg)
268268
self._name = name
269269

@@ -342,7 +342,7 @@ def __str__(self):
342342
return formatted
343343

344344
def __repr__(self):
345-
return f"<{self.__class__.__name__} at {id(self):#x} {self.name!r}>"
345+
return f"<{self.__class__.__name__} at {id(self):#x} {repr(self.name)}>"
346346

347347
def __hash__(self):
348348
msg = f"unhashable type: '{self.__class__.__name__}'"
@@ -512,7 +512,7 @@ def __init__(
512512
param = param.replace(name=name)
513513

514514
if name in params:
515-
msg = f"duplicate parameter name: {name!r}"
515+
msg = f"duplicate parameter name: {repr(name)}"
516516
raise ValueError(msg)
517517
params[name] = param
518518
else:
@@ -526,7 +526,7 @@ def from_function(cls, func):
526526
"""Constructs Signature for the given python function"""
527527

528528
if not isinstance(func, types.FunctionType):
529-
raise TypeError(f"{func!r} is not a Python function")
529+
raise TypeError(f"{repr(func)} is not a Python function")
530530

531531
Parameter = cls._parameter_cls
532532

@@ -707,7 +707,7 @@ def _bind(self, args, kwargs, partial=False):
707707
elif param.name in kwargs:
708708
if param.kind == _POSITIONAL_ONLY:
709709
msg = (
710-
f"{param.name!r} parameter is positional only, "
710+
f"{repr(param.name)} parameter is positional only, "
711711
"but was passed as a keyword"
712712
)
713713
raise TypeError(msg)
@@ -724,7 +724,7 @@ def _bind(self, args, kwargs, partial=False):
724724
parameters_ex = (param,)
725725
break
726726
else:
727-
msg = f"{param.name!r} parameter lacking default value"
727+
msg = f"{repr(param.name)} parameter lacking default value"
728728
raise TypeError(msg)
729729
else:
730730
# We have a positional argument to process
@@ -748,7 +748,9 @@ def _bind(self, args, kwargs, partial=False):
748748
break
749749

750750
if param.name in kwargs:
751-
raise TypeError(f"multiple values for argument {param.name!r}")
751+
raise TypeError(
752+
f"multiple values for argument {repr(param.name)}"
753+
)
752754

753755
arguments[param.name] = arg_val
754756

@@ -761,7 +763,7 @@ def _bind(self, args, kwargs, partial=False):
761763
# Signature object (but let's have this check here
762764
# to ensure correct behaviour just in case)
763765
raise TypeError(
764-
f"{param.name!r} parameter is positional only, "
766+
f"{repr(param.name)} parameter is positional only, "
765767
"but was passed as a keyword"
766768
)
767769

@@ -783,7 +785,9 @@ def _bind(self, args, kwargs, partial=False):
783785
and param.kind != _VAR_POSITIONAL
784786
and param.default is _empty
785787
):
786-
raise TypeError(f"{param_name!r} parameter lacking default value")
788+
raise TypeError(
789+
f"{repr(param_name)} parameter lacking default value"
790+
)
787791

788792
else:
789793
arguments[param_name] = arg_val

graphene/types/tests/test_datetime.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ def test_time_query_variable(sample_time):
169169
def test_bad_variables(sample_date, sample_datetime, sample_time):
170170
def _test_bad_variables(type_, input_):
171171
result = schema.execute(
172-
"""query Test($input: {}){{ {}(in: $input) }}""".format(
173-
type_, type_.lower()
174-
),
172+
f"""query Test($input: {type}){{ {type_.lower()}(in: $input) }}""",
175173
variables={"input": input_},
176174
)
177175
assert len(result.errors) == 1

0 commit comments

Comments
 (0)