Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f6e134

Browse files
klenbrycepg
authored andcommitted
Update Rope refactoring library.
1 parent0500870 commit4f6e134

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 needsmaintainers andcontributors*
9+
*The project needs contributors*
1010

11-
Slack Channel: https://python-mode.herokuapp.com/
11+
** Python-modeSlack 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__.pyrenamed 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
File renamed without changes.

‎pymode/libs2/rope/base/ast.pyrenamed 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
fromrope.baseimportfscommands
55

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

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

‎pymode/libs3/rope/base/astutils.pyrenamed 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
ifself.levelsisnotNone:

‎pymode/libs2/rope/base/builtins.pyrenamed 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
importinspect
3+
try:
4+
raw_input
5+
exceptNameError:
6+
raw_input=input
37

48
importrope.base.evaluate
5-
fromrope.baseimportpynames,pyobjects,arguments,utils,ast
9+
fromrope.base.utilsimportpycompat
10+
fromrope.baseimportpynames,pyobjects,arguments,utils
611

712

813
classBuiltinModule(pyobjects.AbstractModule):
@@ -32,7 +37,7 @@ def attributes(self):
3237
result.update(self.initial)
3338
ifself.pycoreisnotNone:
3439
submodules=self.pycore._builtin_submodules(self.name)
35-
forname,moduleinsubmodules.iteritems():
40+
forname,moduleinsubmodules.items():
3641
result[name]=rope.base.builtins.BuiltinName(module)
3742
returnresult
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+
exceptAttributeError:
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
ifself.holdingisnotNone:
301+
args=context.get_arguments(['self','key'])
302+
if (len(args)>1andargs[1]isnotNoneand
303+
args[1].get_type()==builtins['slice'].get_object()):
304+
returnget_list(self.holding)
293305
returnself.holding
294306
returncontext.get_per_name()
295307

@@ -407,7 +419,7 @@ def __init__(self, *objects):
407419
ifobjects:
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
formethodinself_methods:
496508
collector(method,self_object)
497509

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

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

570589
defadd(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
formethodin ['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
defget_param_names(self,special_args=True):
645-
result= [node.idfornodeinself.arguments.args
646-
ifisinstance(node,ast.Name)]
664+
result= [pycompat.get_ast_arg_arg(node)fornodeinself.arguments.args
665+
ifisinstance(node,pycompat.ast_arg_type)]
647666
ifself.arguments.vararg:
648-
result.append('*'+self.arguments.vararg)
667+
result.append('*'+pycompat.get_ast_arg_arg(self.arguments.vararg))
649668
ifself.arguments.kwarg:
650-
result.append('**'+self.arguments.kwarg)
669+
result.append('**'+pycompat.get_ast_arg_arg(self.arguments.kwarg))
651670
returnresult
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.pyrenamed 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-
exceptIOError,e:
372+
exceptIOErrorase:
373373
raiseexceptions.RopeError(e)
374374

375375

‎pymode/libs2/rope/base/codeanalyze.pyrenamed 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
ifnotself.changes:
2020
returnNone
2121

22-
defcompare_changes(change1,change2):
23-
returncmp(change1[:2],change2[:2])
24-
self.changes.sort(compare_changes)
22+
self.changes.sort(key=lambdax:x[:2])
2523
pieces= []
2624
last_changed=0
2725
forchangeinself.changes:
@@ -131,31 +129,31 @@ def __call__(self):
131129
i+=1
132130
returnresult
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-
formatchinself._main_chars.finditer(line):
139-
char=match.group()
140-
i=match.start()
141-
ifcharin'\'"':
136+
token=None
137+
formatchinself._main_tokens.finditer(line):
138+
prefix=match.group(1)
139+
token=match.group(2)
140+
# Skip any tokens which are escaped
141+
iflen(prefix)%2==1:
142+
continue
143+
iftokenin ["'''",'"""',"'",'"']:
142144
ifnotself.in_string:
143-
self.in_string=char
144-
ifchar*3==line[i:i+3]:
145-
self.in_string=char*3
146-
elifself.in_string==line[i:i+len(self.in_string)]and \
147-
not (i>0andline[i-1]=='\\'and
148-
not (i>1andline[i-2]=='\\')):
145+
self.in_string=token
146+
elifself.in_string==token:
149147
self.in_string=''
150148
ifself.in_string:
151149
continue
152-
ifchar=='#':
150+
iftoken=='#':
153151
break
154-
ifcharin'([{':
152+
iftokenin'([{':
155153
self.open_count+=1
156-
elifcharin')]}':
154+
eliftokenin')]}':
157155
self.open_count-=1
158-
iflineandchar!='#'andline.endswith('\\'):
156+
iflineandtoken!='#'andline.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
returnself._block_logical_line(block_start,line_number)
180-
exceptIndentationError,e:
178+
exceptIndentationErrorase:
181179
tries+=1
182180
iftries==5:
183181
raisee
@@ -222,7 +220,7 @@ def _calculate_logical(self, readline, line_number):
222220
ifline_number<=end:
223221
return (start,end)
224222
last_end=end+1
225-
excepttokenize.TokenError,e:
223+
excepttokenize.TokenErrorase:
226224
current=e.args[1][0]
227225
return (last_end,max(last_end,current-1))
228226
return (last_end,None)

‎pymode/libs2/rope/base/default_config.pyrenamed to‎pymode/libs/rope/base/default_config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# The default ``config.py``
2+
# flake8: noqa
23

34

45
defset_prefs(prefs):
@@ -14,8 +15,10 @@ def set_prefs(prefs):
1415
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
1516
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
1617
prefs['ignored_resources']= [
17-
'*.pyc','*~','.ropeproject','.hg','.svn','_svn','.git',
18-
'.tox','.env','node_modules','bower_components']
18+
'*.pyc','*~','.ropeproject','.hg','.svn','_svn',
19+
'.git','.tox','.env','env','venv','node_modules',
20+
'bower_components'
21+
]
1922

2023
# Specifies which files should be considered python files. It is
2124
# useful when you have scripts inside your project. Only files
@@ -80,6 +83,10 @@ def set_prefs(prefs):
8083
# appear in the importing namespace.
8184
prefs['ignore_bad_imports']=False
8285

86+
# If `True`, rope will insert new module imports as
87+
# `from <package> import <module>` by default.
88+
prefs['prefer_module_from_imports']=False
89+
8390
# If `True`, rope will transform a comma list of imports into
8491
# multiple separate import statements when organizing
8592
# imports.

‎pymode/libs2/rope/base/evaluate.pyrenamed to‎pymode/libs/rope/base/evaluate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
importrope.base.pynames
33
importrope.base.pyobjects
44
fromrope.baseimportast,astutils,exceptions,pyobjects,arguments,worder
5+
fromrope.base.utilsimportpycompat
56

67

78
BadIdentifierError=exceptions.BadIdentifierError
@@ -290,7 +291,11 @@ def _Subscript(self, node):
290291
self._call_function(node.value,'__getitem__',
291292
[node.slice.value])
292293
elifisinstance(node.slice,ast.Slice):
293-
self._call_function(node.value,'__getslice__')
294+
self._call_function(node.value,'__getitem__',
295+
[node.slice])
296+
297+
def_Slice(self,node):
298+
self.result=self._get_builtin_name('slice')
294299

295300
def_call_function(self,node,function_name,other_args=None):
296301
pyname=eval_node(self.scope,node)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp