Skip to content

Commit

Permalink
Upgrading pyupgrade in pre-commit configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Apr 10, 2021
1 parent 9baf996 commit 6c6674e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.10.0
rev: v2.12.0
hooks:
- id: pyupgrade
exclude: tests/testdata
Expand Down
26 changes: 13 additions & 13 deletions astroid/as_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def visit_assignname(self, node):
def visit_assign(self, node):
"""return an astroid.Assign node as string"""
lhs = " = ".join(n.accept(self) for n in node.targets)
return "{} = {}".format(lhs, node.value.accept(self))
return f"{lhs} = {node.value.accept(self)}"

def visit_augassign(self, node):
"""return an astroid.AugAssign node as string"""
Expand All @@ -132,7 +132,7 @@ def visit_annassign(self, node):
annotation = node.annotation.accept(self)
if node.value is None:
return f"{target}: {annotation}"
return "{}: {} = {}".format(target, annotation, node.value.accept(self))
return f"{target}: {annotation} = {node.value.accept(self)}"

def visit_repr(self, node):
"""return an astroid.Repr node as string"""
Expand Down Expand Up @@ -185,11 +185,11 @@ def visit_compare(self, node):
"""return an astroid.Compare node as string"""
rhs_str = " ".join(
[
"{} {}".format(op, self._precedence_parens(node, expr, is_left=False))
f"{op} {self._precedence_parens(node, expr, is_left=False)}"
for op, expr in node.ops
]
)
return "{} {}".format(self._precedence_parens(node, node.left), rhs_str)
return f"{self._precedence_parens(node, node.left)} {rhs_str}"

def visit_comprehension(self, node):
"""return an astroid.Comprehension node as string"""
Expand Down Expand Up @@ -268,7 +268,7 @@ def visit_excepthandler(self, node):
excs = "except %s" % node.type.accept(self)
else:
excs = "except"
return "{}:\n{}".format(excs, self._stmt_list(node.body))
return f"{excs}:\n{self._stmt_list(node.body)}"

def visit_ellipsis(self, node):
"""return an astroid.Ellipsis node as string"""
Expand Down Expand Up @@ -302,7 +302,7 @@ def visit_for(self, node):
node.target.accept(self), node.iter.accept(self), self._stmt_list(node.body)
)
if node.orelse:
fors = "{}\nelse:\n{}".format(fors, self._stmt_list(node.orelse))
fors = f"{fors}\nelse:\n{self._stmt_list(node.orelse)}"
return fors

def visit_importfrom(self, node):
Expand Down Expand Up @@ -392,7 +392,7 @@ def visit_global(self, node):

def visit_if(self, node):
"""return an astroid.If node as string"""
ifs = ["if {}:\n{}".format(node.test.accept(self), self._stmt_list(node.body))]
ifs = [f"if {node.test.accept(self)}:\n{self._stmt_list(node.body)}"]
if node.has_elif_block():
ifs.append("el%s" % self._stmt_list(node.orelse, indent=False))
elif node.orelse:
Expand All @@ -415,7 +415,7 @@ def visit_keyword(self, node):
"""return an astroid.Keyword node as string"""
if node.arg is None:
return "**%s" % node.value.accept(self)
return "{}={}".format(node.arg, node.value.accept(self))
return f"{node.arg}={node.value.accept(self)}"

def visit_lambda(self, node):
"""return an astroid.Lambda node as string"""
Expand Down Expand Up @@ -465,7 +465,7 @@ def visit_print(self, node):
if not node.nl:
nodes = "%s," % nodes
if node.dest:
return "print >> {}, {}".format(node.dest.accept(self), nodes)
return f"print >> {node.dest.accept(self)}, {nodes}"
return "print %s" % nodes

def visit_raise(self, node):
Expand Down Expand Up @@ -522,7 +522,7 @@ def visit_subscript(self, node):
# Remove parenthesis in tuple and extended slice.
# a[(::1, 1:)] is not valid syntax.
idxstr = idxstr[1:-1]
return "{}[{}]".format(self._precedence_parens(node, node.value), idxstr)
return f"{self._precedence_parens(node, node.value)}[{idxstr}]"

def visit_tryexcept(self, node):
"""return an astroid.TryExcept node as string"""
Expand Down Expand Up @@ -551,15 +551,15 @@ def visit_unaryop(self, node):
operator = "not "
else:
operator = node.op
return "{}{}".format(operator, self._precedence_parens(node, node.operand))
return f"{operator}{self._precedence_parens(node, node.operand)}"

def visit_while(self, node):
"""return an astroid.While node as string"""
whiles = "while {}:\n{}".format(
node.test.accept(self), self._stmt_list(node.body)
)
if node.orelse:
whiles = "{}\nelse:\n{}".format(whiles, self._stmt_list(node.orelse))
whiles = f"{whiles}\nelse:\n{self._stmt_list(node.orelse)}"
return whiles

def visit_with(self, node): # 'with' without 'as' is possible
Expand All @@ -568,7 +568,7 @@ def visit_with(self, node): # 'with' without 'as' is possible
("%s" % expr.accept(self)) + (vars and " as %s" % (vars.accept(self)) or "")
for expr, vars in node.items
)
return "with {}:\n{}".format(items, self._stmt_list(node.body))
return f"with {items}:\n{self._stmt_list(node.body)}"

def visit_yield(self, node):
"""yield an ast.Yield node as string"""
Expand Down
2 changes: 1 addition & 1 deletion astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ImportlibFinder(Finder):

def find_module(self, modname, module_parts, processed, submodule_path):
if not isinstance(modname, str):
raise TypeError("'modname' must be a str, not {}".format(type(modname)))
raise TypeError(f"'modname' must be a str, not {type(modname)}")
if submodule_path is not None:
submodule_path = list(submodule_path)
else:
Expand Down
6 changes: 3 additions & 3 deletions astroid/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def _repr_node(node, result, done, cur_indent="", depth=1):
depth += 1
cur_indent += indent
if ids:
result.append("{}<0x{:x}>(\n".format(type(node).__name__, id(node)))
result.append(f"{type(node).__name__}<0x{id(node):x}>(\n")
else:
result.append("%s(" % type(node).__name__)
fields = []
Expand Down Expand Up @@ -2617,7 +2617,7 @@ def getitem(self, index, context=None):

else:
raise exceptions.AstroidTypeError(
"Could not use type {} as subscript index".format(type(index))
f"Could not use type {type(index)} as subscript index"
)

try:
Expand Down Expand Up @@ -2657,7 +2657,7 @@ def itered(self):
"""
if isinstance(self.value, str):
return [const_factory(elem) for elem in self.value]
raise TypeError("Cannot iterate over type {!r}".format(type(self.value)))
raise TypeError(f"Cannot iterate over type {type(self.value)!r}")

def pytype(self):
"""Get the name of the type that this node represents.
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest_brain_numpy_core_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_numpy_function_calls_inferred_as_ndarray(self):
inferred_values = list(self._inferred_numpy_func_call(*func_))
self.assertTrue(
len(inferred_values) == 1,
msg="Too much inferred value for {:s}".format(func_[0]),
msg=f"Too much inferred value for {func_[0]:s}",
)
self.assertTrue(
inferred_values[-1].pytype() in licit_array_types,
Expand Down

0 comments on commit 6c6674e

Please sign in to comment.