Skip to content

Commit

Permalink
Blacken all files
Browse files Browse the repository at this point in the history
Also add pyproject.toml to avoid re-running black on ropetest

black currently has poor multi-line string treatment for dedent()-ed code.

I've ran aneeshusa's black branch psf/black#1879
on ropetest instead, which leaves dedent()-ed lines alone; however
most people likely will be running mainline black which would have
mucked these formatting , so we're adding an exclusion rule in
pyproject.toml prevent people from auto-formatting ropetest.
  • Loading branch information
climbus authored and lieryan committed Sep 26, 2021
1 parent 828e8dc commit b95d3e0
Show file tree
Hide file tree
Showing 123 changed files with 12,914 additions and 11,269 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
@@ -0,0 +1,4 @@
[tool.black]

target-version = ['py27', 'py33', 'py34', 'py35', 'py36', 'py37', 'py38', 'py39']
exclude = 'ropetest'
2 changes: 1 addition & 1 deletion rope/__init__.py
@@ -1,7 +1,7 @@
"""rope, a python refactoring library"""

INFO = __doc__
VERSION = '0.20.1'
VERSION = "0.20.1"
COPYRIGHT = """\
Copyright (C) 2019-2021 Matej Cepl
Copyright (C) 2015-2018 Nicholas Smith
Expand Down
2 changes: 1 addition & 1 deletion rope/base/__init__.py
Expand Up @@ -5,4 +5,4 @@
"""

__all__ = ['project', 'libutils', 'exceptions']
__all__ = ["project", "libutils", "exceptions"]
18 changes: 9 additions & 9 deletions rope/base/arguments.py
Expand Up @@ -47,14 +47,12 @@ def create_arguments(primary, pyfunction, call_node, scope):
args.extend(call_node.keywords)
called = call_node.func
# XXX: Handle constructors
if _is_method_call(primary, pyfunction) and \
isinstance(called, ast.Attribute):
if _is_method_call(primary, pyfunction) and isinstance(called, ast.Attribute):
args.insert(0, called.value)
return Arguments(args, scope)


class ObjectArguments(object):

def __init__(self, pynames):
self.pynames = pynames

Expand All @@ -75,7 +73,6 @@ def get_instance_pyname(self):


class MixedArguments(object):

def __init__(self, pyname, arguments, scope):
"""`argumens` is an instance of `Arguments`"""
self.pyname = pyname
Expand All @@ -101,11 +98,14 @@ def _is_method_call(primary, pyfunction):
if primary is None:
return False
pyobject = primary.get_object()
if isinstance(pyobject.get_type(), rope.base.pyobjects.PyClass) and \
isinstance(pyfunction, rope.base.pyobjects.PyFunction) and \
isinstance(pyfunction.parent, rope.base.pyobjects.PyClass):
if (
isinstance(pyobject.get_type(), rope.base.pyobjects.PyClass)
and isinstance(pyfunction, rope.base.pyobjects.PyFunction)
and isinstance(pyfunction.parent, rope.base.pyobjects.PyClass)
):
return True
if isinstance(pyobject.get_type(), rope.base.pyobjects.AbstractClass) and \
isinstance(pyfunction, rope.base.builtins.BuiltinFunction):
if isinstance(
pyobject.get_type(), rope.base.pyobjects.AbstractClass
) and isinstance(pyfunction, rope.base.builtins.BuiltinFunction):
return True
return False
18 changes: 9 additions & 9 deletions rope/base/ast.py
Expand Up @@ -10,16 +10,16 @@
unicode = str


def parse(source, filename='<string>'):
def parse(source, filename="<string>"):
# NOTE: the raw string should be given to `compile` function
if isinstance(source, unicode):
source = fscommands.unicode_to_file_data(source)
if b'\r' in source:
source = source.replace(b'\r\n', b'\n').replace(b'\r', b'\n')
if not source.endswith(b'\n'):
source += b'\n'
if b"\r" in source:
source = source.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
if not source.endswith(b"\n"):
source += b"\n"
try:
return ast.parse(source, filename='<unknown>')
return ast.parse(source, filename="<unknown>")
except (TypeError, ValueError) as e:
error = SyntaxError()
error.lineno = 1
Expand All @@ -30,13 +30,13 @@ def parse(source, filename='<string>'):

def walk(node, walker):
"""Walk the syntax tree"""
method_name = '_' + node.__class__.__name__
method_name = "_" + node.__class__.__name__
method = getattr(walker, method_name, None)
if method is not None:
if isinstance(node, ast.ImportFrom) and node.module is None:
# In python < 2.7 ``node.module == ''`` for relative imports
# but for python 2.7 it is None. Generalizing it to ''.
node.module = ''
node.module = ""
return method(node)
for child in get_child_nodes(node):
walk(child, walker)
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_children(node):
result = []
if node._fields is not None:
for name in node._fields:
if name in ['lineno', 'col_offset']:
if name in ["lineno", "col_offset"]:
continue
child = getattr(node, name)
result.append(child)
Expand Down
3 changes: 1 addition & 2 deletions rope/base/astutils.py
Expand Up @@ -19,7 +19,6 @@ def get_name_levels(node):


class _NodeNameCollector(object):

def __init__(self, levels=None):
self.names = []
self.levels = levels
Expand All @@ -34,7 +33,7 @@ def _add_node(self, node):
self._added(node, new_levels)

def _added(self, node, levels):
if hasattr(node, 'id'):
if hasattr(node, "id"):
self.names.append((node.id, levels))

def _Name(self, node):
Expand Down

0 comments on commit b95d3e0

Please sign in to comment.