Skip to content

Commit 4f6e134

Browse files
klenbrycepg
authored andcommitted
Update Rope refactoring library.
1 parent 0500870 commit 4f6e134

File tree

153 files changed

+1000
-17188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+1000
-17188
lines changed

README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
-----
88

9-
*The project needs maintainers and contributors*
9+
*The project needs contributors*
1010

11-
Slack Channel: https://python-mode.herokuapp.com/
11+
** Python-mode Slack Channel is here: https://python-mode.herokuapp.com/ **
1212

1313
-----
1414

@@ -180,7 +180,10 @@ at https://github.com/klen/python-mode/issues
180180
Contributing
181181
============
182182

183-
See the `AUTHORS` file.
183+
* Kirill Klenov (horneds@gmail.com)
184+
* Bryce Guinta (https://github.com/brycepg)
185+
186+
Also see the `AUTHORS` file.
184187

185188
Development of python-mode happens at github:
186189
https://github.com/klen/python-mode

pylama.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ linters=pep8,pyflakes,pylint
55
skip=1
66

77
[pylama:pylint]
8-
disable=E1120,E1130,E1103,W1401
8+
disable=E1120,E1130,E1103,W1401,F0001

pymode/libs2/rope/__init__.py renamed to pymode/libs/rope/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""rope, a python refactoring library"""
22

33
INFO = __doc__
4-
VERSION = '0.10.2'
4+
VERSION = '0.10.3'
55
COPYRIGHT = """\
6+
Copyright (C) 2014-2015 Matej Cepl
67
Copyright (C) 2006-2012 Ali Gholami Rudi
78
Copyright (C) 2009-2012 Anton Gritsay
89

pymode/libs2/rope/base/ast.py renamed to pymode/libs/rope/base/ast.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33

44
from rope.base import fscommands
55

6+
try:
7+
unicode
8+
except NameError:
9+
unicode = str
10+
611

712
def parse(source, filename='<string>'):
813
# NOTE: the raw string should be given to `compile` function
914
if isinstance(source, unicode):
1015
source = fscommands.unicode_to_file_data(source)
11-
if '\r' in source:
12-
source = source.replace('\r\n', '\n').replace('\r', '\n')
13-
if not source.endswith('\n'):
14-
source += '\n'
16+
if b'\r' in source:
17+
source = source.replace(b'\r\n', b'\n').replace(b'\r', b'\n')
18+
if not source.endswith(b'\n'):
19+
source += b'\n'
1520
try:
1621
return compile(source, filename, 'exec', _ast.PyCF_ONLY_AST)
17-
except (TypeError, ValueError), e:
22+
except (TypeError, ValueError) as e:
1823
error = SyntaxError()
1924
error.lineno = 1
2025
error.filename = filename

pymode/libs3/rope/base/astutils.py renamed to pymode/libs/rope/base/astutils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def _added(self, node, levels):
4040
def _Name(self, node):
4141
self._add_node(node)
4242

43+
def _ExceptHandler(self, node):
44+
self.names.append((node.name, []))
45+
4346
def _Tuple(self, node):
4447
new_levels = []
4548
if self.levels is not None:

pymode/libs2/rope/base/builtins.py renamed to pymode/libs/rope/base/builtins.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"""This module trys to support builtin types and functions."""
22
import inspect
3+
try:
4+
raw_input
5+
except NameError:
6+
raw_input = input
37

48
import rope.base.evaluate
5-
from rope.base import pynames, pyobjects, arguments, utils, ast
9+
from rope.base.utils import pycompat
10+
from rope.base import pynames, pyobjects, arguments, utils
611

712

813
class BuiltinModule(pyobjects.AbstractModule):
@@ -32,7 +37,7 @@ def attributes(self):
3237
result.update(self.initial)
3338
if self.pycore is not None:
3439
submodules = self.pycore._builtin_submodules(self.name)
35-
for name, module in submodules.iteritems():
40+
for name, module in submodules.items():
3641
result[name] = rope.base.builtins.BuiltinName(module)
3742
return result
3843

@@ -266,7 +271,10 @@ def __init__(self, holding=None):
266271
# Getting methods
267272
collector('__getitem__', function=self._list_get)
268273
collector('pop', function=self._list_get)
269-
collector('__getslice__', function=self._self_get)
274+
try:
275+
collector('__getslice__', function=self._list_get)
276+
except AttributeError:
277+
pass
270278

271279
super(List, self).__init__(list, collector.attributes)
272280

@@ -290,6 +298,10 @@ def _self_set(self, context):
290298

291299
def _list_get(self, context):
292300
if self.holding is not None:
301+
args = context.get_arguments(['self', 'key'])
302+
if (len(args) > 1 and args[1] is not None and
303+
args[1].get_type() == builtins['slice'].get_object()):
304+
return get_list(self.holding)
293305
return self.holding
294306
return context.get_per_name()
295307

@@ -407,7 +419,7 @@ def __init__(self, *objects):
407419
if objects:
408420
first = objects[0]
409421
attributes = {
410-
'__getitem__': BuiltinName(BuiltinFunction(first)),
422+
'__getitem__': BuiltinName(BuiltinFunction(first)), # TODO: add slice support
411423
'__getslice__':
412424
BuiltinName(BuiltinFunction(pyobjects.PyObject(self))),
413425
'__new__': BuiltinName(BuiltinFunction(function=self._new_tuple)),
@@ -487,14 +499,21 @@ def __init__(self):
487499
collector = _AttributeCollector(str)
488500
collector('__iter__', get_iterator(self_object), check_existence=False)
489501

490-
self_methods = ['__getitem__', '__getslice__', 'capitalize', 'center',
491-
'decode', 'encode', 'expandtabs', 'join', 'ljust',
502+
self_methods = ['__getitem__', 'capitalize', 'center',
503+
'encode', 'expandtabs', 'join', 'ljust',
492504
'lower', 'lstrip', 'replace', 'rjust', 'rstrip',
493505
'strip', 'swapcase', 'title', 'translate', 'upper',
494506
'zfill']
495507
for method in self_methods:
496508
collector(method, self_object)
497509

510+
py2_self_methods = ["__getslice__", "decode"]
511+
for method in py2_self_methods:
512+
try:
513+
collector(method, self_object)
514+
except AttributeError:
515+
pass
516+
498517
for method in ['rsplit', 'split', 'splitlines']:
499518
collector(method, get_list(self_object))
500519

@@ -568,7 +587,7 @@ def __init__(self):
568587
attributes = {}
569588

570589
def add(name, returned=None, function=None):
571-
builtin = getattr(file, name, None)
590+
builtin = getattr(open, name, None)
572591
attributes[name] = BuiltinName(
573592
BuiltinFunction(returned=returned, function=function,
574593
builtin=builtin))
@@ -578,7 +597,7 @@ def add(name, returned=None, function=None):
578597
for method in ['close', 'flush', 'lineno', 'isatty', 'seek', 'tell',
579598
'truncate', 'write', 'writelines']:
580599
add(method)
581-
super(File, self).__init__(file, attributes)
600+
super(File, self).__init__(open, attributes)
582601

583602

584603
get_file = _create_builtin_getter(File)
@@ -642,12 +661,12 @@ def get_name(self):
642661
return 'lambda'
643662

644663
def get_param_names(self, special_args=True):
645-
result = [node.id for node in self.arguments.args
646-
if isinstance(node, ast.Name)]
664+
result = [pycompat.get_ast_arg_arg(node) for node in self.arguments.args
665+
if isinstance(node, pycompat.ast_arg_type)]
647666
if self.arguments.vararg:
648-
result.append('*' + self.arguments.vararg)
667+
result.append('*' + pycompat.get_ast_arg_arg(self.arguments.vararg))
649668
if self.arguments.kwarg:
650-
result.append('**' + self.arguments.kwarg)
669+
result.append('**' + pycompat.get_ast_arg_arg(self.arguments.kwarg))
651670
return result
652671

653672
@property
@@ -787,4 +806,4 @@ def _input_function(args):
787806
builtin=raw_input)),
788807
}
789808

790-
builtins = BuiltinModule('__builtin__', initial=_initial_builtins)
809+
builtins = BuiltinModule(pycompat.builtins.__name__, initial=_initial_builtins)

pymode/libs2/rope/base/change.py renamed to pymode/libs/rope/base/change.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def _create_resource(self, file_name, kind='file'):
369369
fscommands.create_file(resource_path)
370370
else:
371371
fscommands.create_folder(resource_path)
372-
except IOError, e:
372+
except IOError as e:
373373
raise exceptions.RopeError(e)
374374

375375

pymode/libs2/rope/base/codeanalyze.py renamed to pymode/libs/rope/base/codeanalyze.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def get_changed(self):
1919
if not self.changes:
2020
return None
2121

22-
def compare_changes(change1, change2):
23-
return cmp(change1[:2], change2[:2])
24-
self.changes.sort(compare_changes)
22+
self.changes.sort(key=lambda x: x[:2])
2523
pieces = []
2624
last_changed = 0
2725
for change in self.changes:
@@ -131,31 +129,31 @@ def __call__(self):
131129
i += 1
132130
return result
133131

134-
_main_chars = re.compile(r'[\'|"|#|\\|\[|\]|\{|\}|\(|\)]')
132+
# Matches all backslashes before the token, to detect escaped quotes
133+
_main_tokens = re.compile(r'(\\*)((\'\'\'|"""|\'|")|#|\[|\]|\{|\}|\(|\))')
135134

136135
def _analyze_line(self, line):
137-
char = None
138-
for match in self._main_chars.finditer(line):
139-
char = match.group()
140-
i = match.start()
141-
if char in '\'"':
136+
token = None
137+
for match in self._main_tokens.finditer(line):
138+
prefix = match.group(1)
139+
token = match.group(2)
140+
# Skip any tokens which are escaped
141+
if len(prefix) % 2 == 1:
142+
continue
143+
if token in ["'''", '"""', "'", '"']:
142144
if not self.in_string:
143-
self.in_string = char
144-
if char * 3 == line[i:i + 3]:
145-
self.in_string = char * 3
146-
elif self.in_string == line[i:i + len(self.in_string)] and \
147-
not (i > 0 and line[i - 1] == '\\' and
148-
not (i > 1 and line[i - 2] == '\\')):
145+
self.in_string = token
146+
elif self.in_string == token:
149147
self.in_string = ''
150148
if self.in_string:
151149
continue
152-
if char == '#':
150+
if token == '#':
153151
break
154-
if char in '([{':
152+
if token in '([{':
155153
self.open_count += 1
156-
elif char in ')]}':
154+
elif token in ')]}':
157155
self.open_count -= 1
158-
if line and char != '#' and line.endswith('\\'):
156+
if line and token != '#' and line.endswith('\\'):
159157
self.continuation = True
160158
else:
161159
self.continuation = False
@@ -177,7 +175,7 @@ def logical_line_in(self, line_number):
177175
block_start = get_block_start(self.lines, line_number, indents)
178176
try:
179177
return self._block_logical_line(block_start, line_number)
180-
except IndentationError, e:
178+
except IndentationError as e:
181179
tries += 1
182180
if tries == 5:
183181
raise e
@@ -222,7 +220,7 @@ def _calculate_logical(self, readline, line_number):
222220
if line_number <= end:
223221
return (start, end)
224222
last_end = end + 1
225-
except tokenize.TokenError, e:
223+
except tokenize.TokenError as e:
226224
current = e.args[1][0]
227225
return (last_end, max(last_end, current - 1))
228226
return (last_end, None)

0 commit comments

Comments
 (0)