Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blacken source code #404

Merged
merged 3 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Migrate code style to Black
ae87aa32c4e1f7d0b6680ebd977c5579e217361e
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

"""

__all__ = ['project', 'libutils', 'exceptions']
__all__ = ["project", "libutils", "exceptions"]
18 changes: 9 additions & 9 deletions rope/base/arguments.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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