Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
auto_py2to3
提交
365328e0
A
auto_py2to3
项目概览
openeuler
/
auto_py2to3
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
auto_py2to3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
365328e0
编写于
8月 04, 2020
作者:
6
61Duke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some flaw according community require
上级
2614e5b2
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
71 addition
and
81 deletion
+71
-81
auto_py2to3/libs/lib2to3/btm_utils.py
auto_py2to3/libs/lib2to3/btm_utils.py
+2
-4
auto_py2to3/libs/lib2to3/fixer_base.py
auto_py2to3/libs/lib2to3/fixer_base.py
+9
-4
auto_py2to3/libs/lib2to3/fixer_util.py
auto_py2to3/libs/lib2to3/fixer_util.py
+23
-31
auto_py2to3/libs/lib2to3/fixes/fix_apply.py
auto_py2to3/libs/lib2to3/fixes/fix_apply.py
+4
-7
auto_py2to3/libs/lib2to3/fixes/fix_dict.py
auto_py2to3/libs/lib2to3/fixes/fix_dict.py
+4
-4
auto_py2to3/libs/lib2to3/fixes/fix_except.py
auto_py2to3/libs/lib2to3/fixes/fix_except.py
+4
-5
auto_py2to3/libs/lib2to3/fixes/fix_exec.py
auto_py2to3/libs/lib2to3/fixes/fix_exec.py
+1
-1
auto_py2to3/libs/lib2to3/fixes/fix_execfile.py
auto_py2to3/libs/lib2to3/fixes/fix_execfile.py
+6
-6
auto_py2to3/libs/lib2to3/fixes/fix_has_key.py
auto_py2to3/libs/lib2to3/fixes/fix_has_key.py
+12
-12
auto_py2to3/libs/lib2to3/fixes/fix_raise.py
auto_py2to3/libs/lib2to3/fixes/fix_raise.py
+4
-4
auto_py2to3/libs/lib2to3/fixes/fix_throw.py
auto_py2to3/libs/lib2to3/fixes/fix_throw.py
+2
-2
auto_py2to3/libs/lib2to3/fixes/fix_tuple_params.py
auto_py2to3/libs/lib2to3/fixes/fix_tuple_params.py
+0
-1
未找到文件。
auto_py2to3/libs/lib2to3/btm_utils.py
浏览文件 @
365328e0
...
...
@@ -19,8 +19,8 @@ class MinNode(object):
pattern tree during the conversion to sets of leaf-to-root
subpatterns"""
def
__init__
(
self
,
type
=
None
,
name
=
None
):
self
.
type
=
type
def
__init__
(
self
,
_
type
=
None
,
name
=
None
):
self
.
type
=
_
type
self
.
name
=
name
self
.
children
=
[]
self
.
leaf
=
False
...
...
@@ -220,9 +220,7 @@ def reduce_tree(node, parent=None):
# reduce to a single occurrence i.e. do nothing
pass
else
:
# TODO: handle {min, max} repeaters
raise
NotImplementedError
pass
# add children
if
details_node
and
new_node
is
not
None
:
...
...
auto_py2to3/libs/lib2to3/fixer_base.py
浏览文件 @
365328e0
...
...
@@ -7,6 +7,8 @@
import
itertools
# Local imports
from
abc
import
ABC
from
.patcomp
import
PatternCompiler
from
.
import
pygram
from
.fixer_util
import
does_tree_import
...
...
@@ -42,7 +44,7 @@ class BaseFix(object):
# manually
# Shortcut for access to Python grammar symbols
syms
=
pygram
.
python_symbols
sym
_
s
=
pygram
.
python_symbols
def
__init__
(
self
,
options
,
log
):
"""Initializer. Subclass may override.
...
...
@@ -52,6 +54,7 @@ class BaseFix(object):
that could be used to customize the fixer through the command line.
log: a list to append warnings and other messages to.
"""
self
.
first_log
=
False
self
.
options
=
options
self
.
log
=
log
self
.
compile_pattern
()
...
...
@@ -115,7 +118,6 @@ class BaseFix(object):
def
log_message
(
self
,
message
):
if
self
.
first_log
:
self
.
first_log
=
False
self
.
log
.
append
(
"### In file %s ###"
%
self
.
filename
)
self
.
log
.
append
(
message
)
...
...
@@ -166,15 +168,18 @@ class BaseFix(object):
pass
class
ConditionalFix
(
BaseFix
):
class
ConditionalFix
(
BaseFix
,
ABC
):
""" Base class for fixers which not execute if an import is found. """
# This is the name of the import which, if found, will cause the test to be skipped
skip_on
=
None
def
__init__
(
self
,
options
,
log
):
super
().
__init__
(
options
,
log
)
self
.
_should_skip
=
None
def
start_tree
(
self
,
*
args
):
super
(
ConditionalFix
,
self
).
start_tree
(
*
args
)
self
.
_should_skip
=
None
def
should_skip
(
self
,
node
):
if
self
.
_should_skip
is
not
None
:
...
...
auto_py2to3/libs/lib2to3/fixer_util.py
浏览文件 @
365328e0
...
...
@@ -127,11 +127,6 @@ def ListComp(xp, fp, it, test=None):
def
FromImport
(
package_name
,
name_leafs
):
""" Return an import statement in the form:
from package import name_leafs"""
# XXX: May not handle dotted imports properly (eg, package_name='foo.bar')
# assert package_name == '.' or '.' not in package_name, "FromImport has "\
# "not been tested with dotted package names -- use at your own "\
# "peril!"
for
leaf
in
name_leafs
:
# Pull the leaves out of their old tree
leaf
.
remove
()
...
...
@@ -221,31 +216,10 @@ def attr_chain(obj, attr):
Yields:
Each successive object in the chain.
"""
next
=
getattr
(
obj
,
attr
)
while
next
:
yield
next
next
=
getattr
(
next
,
attr
)
p0
=
"""for_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
"""
p1
=
"""
power<
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
trailer< '(' node=any ')' >
any*
>
"""
p2
=
"""
power<
( 'sorted' | 'enumerate' )
trailer< '(' arglist<node=any any*> ')' >
any*
>
"""
pats_built
=
False
_next
=
getattr
(
obj
,
attr
)
while
_next
:
yield
_next
_next
=
getattr
(
_next
,
attr
)
def
in_special_context
(
node
):
...
...
@@ -254,7 +228,25 @@ def in_special_context(node):
or an iterator).
See test_map_nochange in test_fixers.py for some examples and tests.
"""
global
p0
,
p1
,
p2
,
pats_built
p0
=
"""for_stmt< 'for' any 'in' node=any ':' any* >
| comp_for< 'for' any 'in' node=any any* >
"""
p1
=
"""
power<
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
trailer< '(' node=any ')' >
any*
>
"""
p2
=
"""
power<
( 'sorted' | 'enumerate' )
trailer< '(' arglist<node=any any*> ')' >
any*
>
"""
pats_built
=
False
if
not
pats_built
:
p0
=
patcomp
.
compile_pattern
(
p0
)
p1
=
patcomp
.
compile_pattern
(
p1
)
...
...
auto_py2to3/libs/lib2to3/fixes/fix_apply.py
浏览文件 @
365328e0
...
...
@@ -30,7 +30,7 @@ class FixApply(fixer_base.BaseFix):
"""
def
transform
(
self
,
node
,
results
):
syms
=
self
.
syms
sym
_
s
=
self
.
syms
assert
results
func
=
results
[
"func"
]
args
=
results
[
"args"
]
...
...
@@ -48,8 +48,8 @@ class FixApply(fixer_base.BaseFix):
return
# Make no change.
prefix
=
node
.
prefix
func
=
func
.
clone
()
if
(
func
.
type
not
in
(
token
.
NAME
,
syms
.
atom
)
and
(
func
.
type
!=
syms
.
power
or
if
(
func
.
type
not
in
(
token
.
NAME
,
sym
_
s
.
atom
)
and
(
func
.
type
!=
sym
_
s
.
power
or
func
.
children
[
-
2
].
type
==
token
.
DOUBLESTAR
)):
# Need to parenthesize
func
=
parenthesize
(
func
)
...
...
@@ -64,8 +64,5 @@ class FixApply(fixer_base.BaseFix):
l_newargs
.
extend
([
Comma
(),
pytree
.
Leaf
(
token
.
DOUBLESTAR
,
"**"
),
kwds
])
l_newargs
[
-
2
].
prefix
=
" "
# that's the ** token
# XXX Sometimes we could be cleverer, e.g. apply(f, (x, y) + t)
# can be translated into f(x, y, *t) instead of f(*(x, y) + t)
# new = pytree.Node(syms.power, (func, ArgList(l_newargs)))
l_newargs
[
-
2
].
prefix
=
" "
return
Call
(
func
,
l_newargs
,
prefix
=
prefix
)
auto_py2to3/libs/lib2to3/fixes/fix_dict.py
浏览文件 @
365328e0
...
...
@@ -54,7 +54,7 @@ class FixDict(fixer_base.BaseFix):
head
=
results
[
"head"
]
method
=
results
[
"method"
][
0
]
# Extract node for method name
tail
=
results
[
"tail"
]
syms
=
self
.
syms
sym
_
s
=
self
.
syms
method_name
=
method
.
value
isiter
=
method_name
.
startswith
(
"iter"
)
isview
=
method_name
.
startswith
(
"view"
)
...
...
@@ -64,17 +64,17 @@ class FixDict(fixer_base.BaseFix):
head
=
[
n
.
clone
()
for
n
in
head
]
tail
=
[
n
.
clone
()
for
n
in
tail
]
special
=
not
tail
and
self
.
in_special_context
(
node
,
isiter
)
args
=
head
+
[
pytree
.
Node
(
syms
.
trailer
,
args
=
head
+
[
pytree
.
Node
(
sym
_
s
.
trailer
,
[
Dot
(),
Name
(
method_name
,
prefix
=
method
.
prefix
)]),
results
[
"parens"
].
clone
()]
new
=
pytree
.
Node
(
syms
.
power
,
args
)
new
=
pytree
.
Node
(
sym
_
s
.
power
,
args
)
if
not
(
special
or
isview
):
new
.
prefix
=
""
new
=
Call
(
Name
(
"iter"
if
isiter
else
"list"
),
[
new
])
if
tail
:
new
=
pytree
.
Node
(
syms
.
power
,
[
new
]
+
tail
)
new
=
pytree
.
Node
(
sym
_
s
.
power
,
[
new
]
+
tail
)
new
.
prefix
=
node
.
prefix
return
new
...
...
auto_py2to3/libs/lib2to3/fixes/fix_except.py
浏览文件 @
365328e0
...
...
@@ -25,12 +25,12 @@ The following cases will be converted:
from
..
import
pytree
from
..pgen2
import
token
from
..
import
fixer_base
from
..fixer_util
import
Assign
,
Attr
,
Name
,
is_tuple
,
is_list
,
syms
from
..fixer_util
import
Assign
,
Attr
,
Name
,
is_tuple
,
is_list
,
sym
_
s
def
find_excepts
(
nodes
):
for
i
,
n
in
enumerate
(
nodes
):
if
n
.
type
==
syms
.
except_clause
:
if
n
.
type
==
sym
_
s
.
except_clause
:
if
n
.
children
[
0
].
value
==
'except'
:
yield
(
n
,
nodes
[
i
+
2
])
...
...
@@ -47,7 +47,7 @@ class FixExcept(fixer_base.BaseFix):
"""
def
transform
(
self
,
node
,
results
):
syms
=
self
.
syms
sym
_
s
=
self
.
syms
tail
=
[
n
.
clone
()
for
n
in
results
[
"tail"
]]
...
...
@@ -70,6 +70,7 @@ class FixExcept(fixer_base.BaseFix):
# and indents
# TODO(cwinter) suite-cleanup
suite_stmts
=
e_suite
.
children
i
=
0
for
i
,
stmt
in
enumerate
(
suite_stmts
):
if
isinstance
(
stmt
,
pytree
.
Node
):
break
...
...
@@ -81,7 +82,6 @@ class FixExcept(fixer_base.BaseFix):
else
:
assign
=
Assign
(
target
,
new_N
)
# TODO(cwinter) stopgap until children becomes a smart list
for
child
in
reversed
(
suite_stmts
[:
i
]):
e_suite
.
insert_child
(
0
,
child
)
e_suite
.
insert_child
(
i
,
assign
)
...
...
@@ -90,6 +90,5 @@ class FixExcept(fixer_base.BaseFix):
# not so much.
N
.
prefix
=
" "
# TODO(cwinter) fix this when children becomes a smart list
children
=
[
c
.
clone
()
for
c
in
node
.
children
[:
3
]]
+
try_cleanup
+
tail
return
pytree
.
Node
(
node
.
type
,
children
)
auto_py2to3/libs/lib2to3/fixes/fix_exec.py
浏览文件 @
365328e0
...
...
@@ -25,7 +25,7 @@ class FixExec(fixer_base.BaseFix):
def
transform
(
self
,
node
,
results
):
assert
results
syms
=
self
.
syms
sym
_
s
=
self
.
syms
a
=
results
[
"a"
]
b
=
results
.
get
(
"b"
)
c
=
results
.
get
(
"c"
)
...
...
auto_py2to3/libs/lib2to3/fixes/fix_execfile.py
浏览文件 @
365328e0
...
...
@@ -24,8 +24,8 @@ class FixExecfile(fixer_base.BaseFix):
def
transform
(
self
,
node
,
results
):
assert
results
filename
=
results
[
"filename"
]
globals
=
results
.
get
(
"globals"
)
locals
=
results
.
get
(
"locals"
)
tmp_
globals
=
results
.
get
(
"globals"
)
tmp_
locals
=
results
.
get
(
"locals"
)
# Copy over the prefix from the right parentheses end of the execfile
# call.
...
...
@@ -46,8 +46,8 @@ class FixExecfile(fixer_base.BaseFix):
compile_call
=
Call
(
Name
(
"compile"
),
compile_args
,
""
)
# Finally, replace the execfile call with an exec call.
args
=
[
compile_call
]
if
globals
is
not
None
:
args
.
extend
([
Comma
(),
globals
.
clone
()])
if
locals
is
not
None
:
args
.
extend
([
Comma
(),
locals
.
clone
()])
if
tmp_
globals
is
not
None
:
args
.
extend
([
Comma
(),
tmp_
globals
.
clone
()])
if
tmp_
locals
is
not
None
:
args
.
extend
([
Comma
(),
tmp_
locals
.
clone
()])
return
Call
(
Name
(
"exec"
),
args
,
prefix
=
node
.
prefix
)
auto_py2to3/libs/lib2to3/fixes/fix_has_key.py
浏览文件 @
365328e0
...
...
@@ -70,8 +70,8 @@ class FixHasKey(fixer_base.BaseFix):
def
transform
(
self
,
node
,
results
):
assert
results
syms
=
self
.
syms
if
(
node
.
parent
.
type
==
syms
.
not_test
and
sym
_
s
=
self
.
syms
if
(
node
.
parent
.
type
==
sym
_
s
.
not_test
and
self
.
pattern
.
match
(
node
.
parent
)):
# Don't transform a node matching the first alternative of the
# pattern when its parent matches the second alternative
...
...
@@ -84,26 +84,26 @@ class FixHasKey(fixer_base.BaseFix):
after
=
results
.
get
(
"after"
)
if
after
:
after
=
[
n
.
clone
()
for
n
in
after
]
if
arg
.
type
in
(
sym
s
.
comparison
,
syms
.
not_test
,
sym
s
.
and_test
,
sym
s
.
or_test
,
syms
.
test
,
syms
.
lambdef
,
sym
s
.
argument
):
if
arg
.
type
in
(
sym
_s
.
comparison
,
sym_s
.
not_test
,
sym_
s
.
and_test
,
sym
_s
.
or_test
,
sym_s
.
test
,
sym_s
.
lambdef
,
sym_
s
.
argument
):
arg
=
parenthesize
(
arg
)
if
len
(
before
)
==
1
:
before
=
before
[
0
]
else
:
before
=
pytree
.
Node
(
syms
.
power
,
before
)
before
=
pytree
.
Node
(
sym
_
s
.
power
,
before
)
before
.
prefix
=
" "
n_op
=
Name
(
"in"
,
prefix
=
" "
)
if
negation
:
n_not
=
Name
(
"not"
,
prefix
=
" "
)
n_op
=
pytree
.
Node
(
syms
.
comp_op
,
(
n_not
,
n_op
))
new
=
pytree
.
Node
(
syms
.
comparison
,
(
arg
,
n_op
,
before
))
n_op
=
pytree
.
Node
(
sym
_
s
.
comp_op
,
(
n_not
,
n_op
))
new
=
pytree
.
Node
(
sym
_
s
.
comparison
,
(
arg
,
n_op
,
before
))
if
after
:
new
=
parenthesize
(
new
)
new
=
pytree
.
Node
(
syms
.
power
,
(
new
,)
+
tuple
(
after
))
if
node
.
parent
.
type
in
(
sym
s
.
comparison
,
syms
.
expr
,
sym
s
.
xor_expr
,
sym
s
.
and_expr
,
sym
s
.
shift_expr
,
sym
s
.
arith_expr
,
sym
s
.
term
,
sym
s
.
factor
,
sym
s
.
power
):
new
=
pytree
.
Node
(
sym
_
s
.
power
,
(
new
,)
+
tuple
(
after
))
if
node
.
parent
.
type
in
(
sym
_s
.
comparison
,
sym_s
.
expr
,
sym_
s
.
xor_expr
,
sym
_s
.
and_expr
,
sym_
s
.
shift_expr
,
sym
_s
.
arith_expr
,
sym_
s
.
term
,
sym
_s
.
factor
,
sym_
s
.
power
):
new
=
parenthesize
(
new
)
new
.
prefix
=
prefix
return
new
auto_py2to3/libs/lib2to3/fixes/fix_raise.py
浏览文件 @
365328e0
...
...
@@ -36,7 +36,7 @@ class FixRaise(fixer_base.BaseFix):
"""
def
transform
(
self
,
node
,
results
):
syms
=
self
.
syms
sym
_
s
=
self
.
syms
exc
=
results
[
"exc"
].
clone
()
if
exc
.
type
==
token
.
STRING
:
...
...
@@ -59,7 +59,7 @@ class FixRaise(fixer_base.BaseFix):
if
"val"
not
in
results
:
# One-argument raise
new
=
pytree
.
Node
(
syms
.
raise_stmt
,
[
Name
(
"raise"
),
exc
])
new
=
pytree
.
Node
(
sym
_
s
.
raise_stmt
,
[
Name
(
"raise"
),
exc
])
new
.
prefix
=
node
.
prefix
return
new
...
...
@@ -81,10 +81,10 @@ class FixRaise(fixer_base.BaseFix):
if
val
.
type
!=
token
.
NAME
or
val
.
value
!=
"None"
:
e
=
Call
(
exc
,
args
)
with_tb
=
Attr
(
e
,
Name
(
'with_traceback'
))
+
[
ArgList
([
tb
])]
new
=
pytree
.
Node
(
syms
.
simple_stmt
,
[
Name
(
"raise"
)]
+
with_tb
)
new
=
pytree
.
Node
(
sym
_
s
.
simple_stmt
,
[
Name
(
"raise"
)]
+
with_tb
)
new
.
prefix
=
node
.
prefix
return
new
else
:
return
pytree
.
Node
(
syms
.
raise_stmt
,
return
pytree
.
Node
(
sym
_
s
.
raise_stmt
,
[
Name
(
"raise"
),
Call
(
exc
,
args
)],
prefix
=
node
.
prefix
)
auto_py2to3/libs/lib2to3/fixes/fix_throw.py
浏览文件 @
365328e0
...
...
@@ -25,7 +25,7 @@ class FixThrow(fixer_base.BaseFix):
"""
def
transform
(
self
,
node
,
results
):
syms
=
self
.
syms
sym
_
s
=
self
.
syms
exc
=
results
[
"exc"
].
clone
()
if
exc
.
type
is
token
.
STRING
:
...
...
@@ -52,6 +52,6 @@ class FixThrow(fixer_base.BaseFix):
e
=
Call
(
exc
,
args
)
with_tb
=
Attr
(
e
,
Name
(
'with_traceback'
))
+
[
ArgList
([
tb
])]
throw_args
.
replace
(
pytree
.
Node
(
syms
.
power
,
with_tb
))
throw_args
.
replace
(
pytree
.
Node
(
sym
_
s
.
power
,
with_tb
))
else
:
throw_args
.
replace
(
Call
(
exc
,
args
))
auto_py2to3/libs/lib2to3/fixes/fix_tuple_params.py
浏览文件 @
365328e0
...
...
@@ -94,7 +94,6 @@ class FixTupleParams(fixer_base.BaseFix):
for
line
in
new_lines
:
line
.
parent
=
suite
[
0
]
# TODO(cwinter) suite-cleanup
after
=
start
if
start
==
0
:
new_lines
[
0
].
prefix
=
" "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录