Skip to content

Commit 12ee52a

Browse files
dan98765jkimbo
authored andcommitted
Add pyupgrade pre-commit hook and run on all files (#736)
1 parent 1b3e7f3 commit 12ee52a

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ repos:
1717
args:
1818
- --autofix
1919
- id: flake8
20+
- repo: https://github.com/asottile/pyupgrade
21+
rev: v1.2.0
22+
hooks:
23+
- id: pyupgrade
2024
- repo: https://github.com/asottile/seed-isort-config
2125
rev: v1.0.0
2226
hooks:

graphene/pyutils/enum.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def __new__(metacls, cls, bases, classdict):
170170
first_enum)
171171
# save enum items into separate mapping so they don't get baked into
172172
# the new class
173-
members = dict((k, classdict[k]) for k in classdict._member_names)
173+
members = {k: classdict[k] for k in classdict._member_names}
174174
for name in classdict._member_names:
175175
del classdict[name]
176176

@@ -192,14 +192,14 @@ def __new__(metacls, cls, bases, classdict):
192192
_order_ += aliases
193193

194194
# check for illegal enum names (any others?)
195-
invalid_names = set(members) & set(['mro'])
195+
invalid_names = set(members) & {'mro'}
196196
if invalid_names:
197197
raise ValueError('Invalid enum member name(s): %s' % (
198198
', '.join(invalid_names), ))
199199

200200
# save attributes from super classes so we know if we can take
201201
# the shortcut of storing members in the class dict
202-
base_attributes = set([a for b in bases for a in b.__dict__])
202+
base_attributes = {a for b in bases for a in b.__dict__}
203203
# create our new Enum type
204204
enum_class = super(EnumMeta, metacls).__new__(metacls, cls, bases, classdict)
205205
enum_class._member_names_ = [] # names in random order
@@ -831,7 +831,7 @@ def _convert(cls, name, module, filter, source=None):
831831
source = vars(source)
832832
else:
833833
source = module_globals
834-
members = dict((name, value) for name, value in source.items() if filter(name))
834+
members = {name: value for name, value in source.items() if filter(name)}
835835
cls = cls(name, members, module=module)
836836
cls.__reduce_ex__ = _reduce_ex_by_name
837837
module_globals.update(cls.__members__)

graphene/pyutils/signature.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def signature(obj):
5252
'''Get a signature object for the passed callable.'''
5353

5454
if not callable(obj):
55-
raise TypeError('{0!r} is not a callable object'.format(obj))
55+
raise TypeError('{!r} is not a callable object'.format(obj))
5656

5757
if isinstance(obj, types.MethodType):
5858
sig = signature(obj.__func__)
@@ -99,7 +99,7 @@ def signature(obj):
9999
try:
100100
ba = sig.bind_partial(*partial_args, **partial_keywords)
101101
except TypeError as ex:
102-
msg = 'partial object {0!r} has incorrect arguments'.format(obj)
102+
msg = 'partial object {!r} has incorrect arguments'.format(obj)
103103
raise ValueError(msg)
104104

105105
for arg_name, arg_value in ba.arguments.items():
@@ -166,10 +166,10 @@ def signature(obj):
166166

167167
if isinstance(obj, types.BuiltinFunctionType):
168168
# Raise a nicer error message for builtins
169-
msg = 'no signature found for builtin function {0!r}'.format(obj)
169+
msg = 'no signature found for builtin function {!r}'.format(obj)
170170
raise ValueError(msg)
171171

172-
raise ValueError('callable {0!r} is not supported by signature'.format(obj))
172+
raise ValueError('callable {!r} is not supported by signature'.format(obj))
173173

174174

175175
class _void(object):
@@ -190,7 +190,7 @@ def __str__(self):
190190
return self._name
191191

192192
def __repr__(self):
193-
return '<_ParameterKind: {0!r}>'.format(self._name)
193+
return '<_ParameterKind: {!r}>'.format(self._name)
194194

195195

196196
_POSITIONAL_ONLY = _ParameterKind(0, name='POSITIONAL_ONLY')
@@ -238,7 +238,7 @@ def __init__(self, name, kind, default=_empty, annotation=_empty,
238238

239239
if default is not _empty:
240240
if kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
241-
msg = '{0} parameters cannot have default values'.format(kind)
241+
msg = '{} parameters cannot have default values'.format(kind)
242242
raise ValueError(msg)
243243
self._default = default
244244
self._annotation = annotation
@@ -251,7 +251,7 @@ def __init__(self, name, kind, default=_empty, annotation=_empty,
251251
else:
252252
name = str(name)
253253
if kind != _POSITIONAL_ONLY and not re.match(r'[a-z_]\w*$', name, re.I):
254-
msg = '{0!r} is not a valid parameter name'.format(name)
254+
msg = '{!r} is not a valid parameter name'.format(name)
255255
raise ValueError(msg)
256256
self._name = name
257257

@@ -302,15 +302,15 @@ def __str__(self):
302302
if kind == _POSITIONAL_ONLY:
303303
if formatted is None:
304304
formatted = ''
305-
formatted = '<{0}>'.format(formatted)
305+
formatted = '<{}>'.format(formatted)
306306

307307
# Add annotation and default value
308308
if self._annotation is not _empty:
309-
formatted = '{0}:{1}'.format(formatted,
309+
formatted = '{}:{}'.format(formatted,
310310
formatannotation(self._annotation))
311311

312312
if self._default is not _empty:
313-
formatted = '{0}={1}'.format(formatted, repr(self._default))
313+
formatted = '{}={}'.format(formatted, repr(self._default))
314314

315315
if kind == _VAR_POSITIONAL:
316316
formatted = '*' + formatted
@@ -320,11 +320,11 @@ def __str__(self):
320320
return formatted
321321

322322
def __repr__(self):
323-
return '<{0} at {1:#x} {2!r}>'.format(self.__class__.__name__,
323+
return '<{} at {:#x} {!r}>'.format(self.__class__.__name__,
324324
id(self), self.name)
325325

326326
def __hash__(self):
327-
msg = "unhashable type: '{0}'".format(self.__class__.__name__)
327+
msg = "unhashable type: '{}'".format(self.__class__.__name__)
328328
raise TypeError(msg)
329329

330330
def __eq__(self, other):
@@ -421,7 +421,7 @@ def kwargs(self):
421421
return kwargs
422422

423423
def __hash__(self):
424-
msg = "unhashable type: '{0}'".format(self.__class__.__name__)
424+
msg = "unhashable type: '{}'".format(self.__class__.__name__)
425425
raise TypeError(msg)
426426

427427
def __eq__(self, other):
@@ -489,7 +489,7 @@ def __init__(self, parameters=None, return_annotation=_empty,
489489
param = param.replace(name=name)
490490

491491
if name in params:
492-
msg = 'duplicate parameter name: {0!r}'.format(name)
492+
msg = 'duplicate parameter name: {!r}'.format(name)
493493
raise ValueError(msg)
494494
params[name] = param
495495
else:
@@ -504,7 +504,7 @@ def from_function(cls, func):
504504
'''Constructs Signature for the given python function'''
505505

506506
if not isinstance(func, types.FunctionType):
507-
raise TypeError('{0!r} is not a Python function'.format(func))
507+
raise TypeError('{!r} is not a Python function'.format(func))
508508

509509
Parameter = cls._parameter_cls
510510

@@ -599,7 +599,7 @@ def replace(self, parameters=_void, return_annotation=_void):
599599
return_annotation=return_annotation)
600600

601601
def __hash__(self):
602-
msg = "unhashable type: '{0}'".format(self.__class__.__name__)
602+
msg = "unhashable type: '{}'".format(self.__class__.__name__)
603603
raise TypeError(msg)
604604

605605
def __eq__(self, other):
@@ -608,8 +608,8 @@ def __eq__(self, other):
608608
len(self.parameters) != len(other.parameters)):
609609
return False
610610

611-
other_positions = dict((param, idx)
612-
for idx, param in enumerate(other.parameters.keys()))
611+
other_positions = {param: idx
612+
for idx, param in enumerate(other.parameters.keys())}
613613

614614
for idx, (param_name, param) in enumerate(self.parameters.items()):
615615
if param.kind == _KEYWORD_ONLY:
@@ -799,10 +799,10 @@ def __str__(self):
799799

800800
result.append(formatted)
801801

802-
rendered = '({0})'.format(', '.join(result))
802+
rendered = '({})'.format(', '.join(result))
803803

804804
if self.return_annotation is not _empty:
805805
anno = formatannotation(self.return_annotation)
806-
rendered += ' -> {0}'.format(anno)
806+
rendered += ' -> {}'.format(anno)
807807

808808
return rendered

graphene/types/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __setattr__(self, name, value):
1818
if not self._frozen:
1919
super(BaseOptions, self).__setattr__(name, value)
2020
else:
21-
raise Exception("Can't modify frozen Options {0}".format(self))
21+
raise Exception("Can't modify frozen Options {}".format(self))
2222

2323
def __repr__(self):
2424
return "<{} name={}>".format(self.__class__.__name__, repr(self.name))

0 commit comments

Comments
 (0)