Skip to content

Commit

Permalink
More f-strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
changeling committed Jun 2, 2019
1 parent b6017bd commit dd09704
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
5 changes: 1 addition & 4 deletions UPGRADE-v2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,7 @@ class Base(ObjectType):
id = ID()

def resolve_id(self, info):
return "{type}_{id}".format(
type=self.__class__.__name__,
id=self.id
)
return f"{self.__class__.__name__}_{self.id}"
```

### UUID Scalar
Expand Down
2 changes: 1 addition & 1 deletion docs/relay/nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Example of a custom node:
@staticmethod
def to_global_id(type, id):
return '{}:{}'.format(type, id)
return f'{type}:{id}'
@staticmethod
def get_node_from_global_id(info, global_id, only_type=None):
Expand Down
4 changes: 2 additions & 2 deletions docs/types/objecttypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This example model defines a Person, with a first and a last name:
full_name = graphene.String()
def resolve_full_name(root, info):
return '{} {}'.format(root.first_name, root.last_name)
return f'{root.first_name} {root.last_name}'
**first\_name** and **last\_name** are fields of the ObjectType. Each
field is specified as a class attribute, and each attribute maps to a
Expand Down Expand Up @@ -173,7 +173,7 @@ A field can use a custom resolver from outside the class:
import graphene
def resolve_full_name(person, info):
return '{} {}'.format(person.first_name, person.last_name)
return f'{person.first_name} {person.last_name}'
class Person(graphene.ObjectType):
first_name = graphene.String()
Expand Down
32 changes: 18 additions & 14 deletions graphene/pyutils/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def signature(obj):
"""Get a signature object for the passed callable."""

if not callable(obj):
raise TypeError(f"{obj!r} is not a callable object")
raise TypeError(f"{repr(obj)} is not a callable object")

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

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

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

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


class _void(object):
Expand All @@ -195,7 +195,7 @@ def __str__(self):
return self._name

def __repr__(self):
return f"<_ParameterKind: {self._name!r}>"
return f"<_ParameterKind: {repr(self._name)}>"


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

Expand Down Expand Up @@ -342,7 +342,7 @@ def __str__(self):
return formatted

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

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

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

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

Parameter = cls._parameter_cls

Expand Down Expand Up @@ -707,7 +707,7 @@ def _bind(self, args, kwargs, partial=False):
elif param.name in kwargs:
if param.kind == _POSITIONAL_ONLY:
msg = (
f"{param.name!r} parameter is positional only, "
f"{repr(param.name)} parameter is positional only, "
"but was passed as a keyword"
)
raise TypeError(msg)
Expand All @@ -724,7 +724,7 @@ def _bind(self, args, kwargs, partial=False):
parameters_ex = (param,)
break
else:
msg = f"{param.name!r} parameter lacking default value"
msg = f"{repr(param.name)} parameter lacking default value"
raise TypeError(msg)
else:
# We have a positional argument to process
Expand All @@ -748,7 +748,9 @@ def _bind(self, args, kwargs, partial=False):
break

if param.name in kwargs:
raise TypeError(f"multiple values for argument {param.name!r}")
raise TypeError(
f"multiple values for argument {repr(param.name)}"
)

arguments[param.name] = arg_val

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

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

else:
arguments[param_name] = arg_val
Expand Down
4 changes: 1 addition & 3 deletions graphene/types/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ def test_time_query_variable(sample_time):
def test_bad_variables(sample_date, sample_datetime, sample_time):
def _test_bad_variables(type_, input_):
result = schema.execute(
"""query Test($input: {}){{ {}(in: $input) }}""".format(
type_, type_.lower()
),
f"""query Test($input: {type}){{ {type_.lower()}(in: $input) }}""",
variables={"input": input_},
)
assert len(result.errors) == 1
Expand Down

0 comments on commit dd09704

Please sign in to comment.