summaryrefslogtreecommitdiff
path: root/Lib/lib2to3/fixes
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-10-14 23:00:00 +0000
committerBenjamin Peterson <benjamin@python.org>2010-10-14 23:00:00 +0000
commitb892bc2e2aea5907ae32b4136f8028b87c09c281 (patch)
tree995d3cad5ff389ea191f288a299adf2e1e3dd780 /Lib/lib2to3/fixes
parentc2efcadf5cdf04b1caede9a9742764e4d3f79a3a (diff)
downloadcpython-b892bc2e2aea5907ae32b4136f8028b87c09c281.tar.gz
Merged revisions 83852-83853,83857,84042,84216,84274-84276,84375,85388,85478,85506-85508 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r83852 | benjamin.peterson | 2010-08-08 15:45:44 -0500 (Sun, 08 Aug 2010) | 1 line wrap with parens ........ r83853 | benjamin.peterson | 2010-08-08 15:46:31 -0500 (Sun, 08 Aug 2010) | 1 line use parens ........ r83857 | benjamin.peterson | 2010-08-08 15:59:49 -0500 (Sun, 08 Aug 2010) | 1 line things which use touch_import should be pre order ........ r84042 | george.boutsioukis | 2010-08-14 16:10:19 -0500 (Sat, 14 Aug 2010) | 2 lines This revision incorporates into the 2to3 tool the new, faster, tree matching algorithm developed during a GSOC project. The algorithm resides in the two added modules, btm_matcher and btm_utils. New code has been added to drive the new matching process in refactor.py and a few minor changes were made in other modules. A BM_compatible flag(False by default) has been added in fixer_base and it is set to True in most of the current fixers. ........ r84216 | benjamin.peterson | 2010-08-19 16:44:05 -0500 (Thu, 19 Aug 2010) | 1 line allow star_expr in testlist_gexp ........ r84274 | benjamin.peterson | 2010-08-22 18:40:46 -0500 (Sun, 22 Aug 2010) | 1 line wrap long line ........ r84275 | benjamin.peterson | 2010-08-22 18:42:22 -0500 (Sun, 22 Aug 2010) | 1 line cleanup ........ r84276 | benjamin.peterson | 2010-08-22 18:51:01 -0500 (Sun, 22 Aug 2010) | 1 line when there's a None value and a traceback, don't call type with it #9661 ........ r84375 | george.boutsioukis | 2010-08-31 08:38:53 -0500 (Tue, 31 Aug 2010) | 3 lines Idiomatic code changes & stylistic issues fixed in the BottomMatcher module. Thanks to Benjamin Peterson for taking the time to review the code. ........ r85388 | benjamin.peterson | 2010-10-12 17:27:44 -0500 (Tue, 12 Oct 2010) | 1 line fix urllib fixer with multiple as imports on a line #10069 ........ r85478 | benjamin.peterson | 2010-10-14 08:09:56 -0500 (Thu, 14 Oct 2010) | 1 line stop abusing docstrings ........ r85506 | benjamin.peterson | 2010-10-14 17:45:19 -0500 (Thu, 14 Oct 2010) | 1 line kill sibling import ........ r85507 | benjamin.peterson | 2010-10-14 17:54:15 -0500 (Thu, 14 Oct 2010) | 1 line remove trailing whitespace ........ r85508 | benjamin.peterson | 2010-10-14 17:55:28 -0500 (Thu, 14 Oct 2010) | 1 line typo ........
Diffstat (limited to 'Lib/lib2to3/fixes')
-rw-r--r--Lib/lib2to3/fixes/fix_apply.py1
-rw-r--r--Lib/lib2to3/fixes/fix_basestring.py1
-rw-r--r--Lib/lib2to3/fixes/fix_buffer.py1
-rw-r--r--Lib/lib2to3/fixes/fix_callable.py3
-rw-r--r--Lib/lib2to3/fixes/fix_dict.py2
-rw-r--r--Lib/lib2to3/fixes/fix_except.py1
-rw-r--r--Lib/lib2to3/fixes/fix_exec.py1
-rw-r--r--Lib/lib2to3/fixes/fix_execfile.py1
-rw-r--r--Lib/lib2to3/fixes/fix_exitfunc.py2
-rw-r--r--Lib/lib2to3/fixes/fix_filter.py1
-rw-r--r--Lib/lib2to3/fixes/fix_funcattrs.py2
-rw-r--r--Lib/lib2to3/fixes/fix_future.py2
-rw-r--r--Lib/lib2to3/fixes/fix_getcwdu.py1
-rw-r--r--Lib/lib2to3/fixes/fix_has_key.py1
-rw-r--r--Lib/lib2to3/fixes/fix_idioms.py1
-rw-r--r--Lib/lib2to3/fixes/fix_import.py1
-rw-r--r--Lib/lib2to3/fixes/fix_imports.py2
-rw-r--r--Lib/lib2to3/fixes/fix_input.py2
-rw-r--r--Lib/lib2to3/fixes/fix_intern.py2
-rw-r--r--Lib/lib2to3/fixes/fix_isinstance.py2
-rw-r--r--Lib/lib2to3/fixes/fix_itertools.py1
-rw-r--r--Lib/lib2to3/fixes/fix_itertools_imports.py1
-rw-r--r--Lib/lib2to3/fixes/fix_long.py2
-rw-r--r--Lib/lib2to3/fixes/fix_map.py1
-rw-r--r--Lib/lib2to3/fixes/fix_metaclass.py1
-rw-r--r--Lib/lib2to3/fixes/fix_methodattrs.py1
-rw-r--r--Lib/lib2to3/fixes/fix_next.py1
-rw-r--r--Lib/lib2to3/fixes/fix_nonzero.py1
-rw-r--r--Lib/lib2to3/fixes/fix_operator.py25
-rw-r--r--Lib/lib2to3/fixes/fix_paren.py2
-rw-r--r--Lib/lib2to3/fixes/fix_print.py2
-rw-r--r--Lib/lib2to3/fixes/fix_raise.py16
-rw-r--r--Lib/lib2to3/fixes/fix_raw_input.py1
-rw-r--r--Lib/lib2to3/fixes/fix_reduce.py3
-rw-r--r--Lib/lib2to3/fixes/fix_renames.py1
-rw-r--r--Lib/lib2to3/fixes/fix_repr.py1
-rw-r--r--Lib/lib2to3/fixes/fix_set_literal.py1
-rw-r--r--Lib/lib2to3/fixes/fix_standarderror.py2
-rw-r--r--Lib/lib2to3/fixes/fix_sys_exc.py1
-rw-r--r--Lib/lib2to3/fixes/fix_throw.py2
-rw-r--r--Lib/lib2to3/fixes/fix_tuple_params.py4
-rw-r--r--Lib/lib2to3/fixes/fix_types.py2
-rw-r--r--Lib/lib2to3/fixes/fix_unicode.py2
-rw-r--r--Lib/lib2to3/fixes/fix_urllib.py31
-rw-r--r--Lib/lib2to3/fixes/fix_xrange.py2
-rw-r--r--Lib/lib2to3/fixes/fix_xreadlines.py1
-rw-r--r--Lib/lib2to3/fixes/fix_zip.py1
47 files changed, 108 insertions, 31 deletions
diff --git a/Lib/lib2to3/fixes/fix_apply.py b/Lib/lib2to3/fixes/fix_apply.py
index 6d1c5d9ed4..a7dc3a046d 100644
--- a/Lib/lib2to3/fixes/fix_apply.py
+++ b/Lib/lib2to3/fixes/fix_apply.py
@@ -12,6 +12,7 @@ from .. import fixer_base
from ..fixer_util import Call, Comma, parenthesize
class FixApply(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< 'apply'
diff --git a/Lib/lib2to3/fixes/fix_basestring.py b/Lib/lib2to3/fixes/fix_basestring.py
index 0de6c26e9d..a3c9a43649 100644
--- a/Lib/lib2to3/fixes/fix_basestring.py
+++ b/Lib/lib2to3/fixes/fix_basestring.py
@@ -6,6 +6,7 @@ from .. import fixer_base
from ..fixer_util import Name
class FixBasestring(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = "'basestring'"
diff --git a/Lib/lib2to3/fixes/fix_buffer.py b/Lib/lib2to3/fixes/fix_buffer.py
index 1c1c4a128b..c6b0928024 100644
--- a/Lib/lib2to3/fixes/fix_buffer.py
+++ b/Lib/lib2to3/fixes/fix_buffer.py
@@ -9,6 +9,7 @@ from ..fixer_util import Name
class FixBuffer(fixer_base.BaseFix):
+ BM_compatible = True
explicit = True # The user must ask for this fixer
diff --git a/Lib/lib2to3/fixes/fix_callable.py b/Lib/lib2to3/fixes/fix_callable.py
index ca5d20b3ea..df33d614ba 100644
--- a/Lib/lib2to3/fixes/fix_callable.py
+++ b/Lib/lib2to3/fixes/fix_callable.py
@@ -11,6 +11,9 @@ from lib2to3 import fixer_base
from lib2to3.fixer_util import Call, Name, String, Attr, touch_import
class FixCallable(fixer_base.BaseFix):
+ BM_compatible = True
+
+ order = "pre"
# Ignore callable(*args) or use of keywords.
# Either could be a hint that the builtin callable() is not being used.
diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py
index 5912cbf611..f681e4d713 100644
--- a/Lib/lib2to3/fixes/fix_dict.py
+++ b/Lib/lib2to3/fixes/fix_dict.py
@@ -40,6 +40,8 @@ iter_exempt = fixer_util.consuming_calls | set(["iter"])
class FixDict(fixer_base.BaseFix):
+ BM_compatible = True
+
PATTERN = """
power< head=any+
trailer< '.' method=('keys'|'items'|'values'|
diff --git a/Lib/lib2to3/fixes/fix_except.py b/Lib/lib2to3/fixes/fix_except.py
index 8118058b7f..e324718f64 100644
--- a/Lib/lib2to3/fixes/fix_except.py
+++ b/Lib/lib2to3/fixes/fix_except.py
@@ -34,6 +34,7 @@ def find_excepts(nodes):
yield (n, nodes[i+2])
class FixExcept(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
try_stmt< 'try' ':' (simple_stmt | suite)
diff --git a/Lib/lib2to3/fixes/fix_exec.py b/Lib/lib2to3/fixes/fix_exec.py
index 121431c0c2..50e1854454 100644
--- a/Lib/lib2to3/fixes/fix_exec.py
+++ b/Lib/lib2to3/fixes/fix_exec.py
@@ -16,6 +16,7 @@ from ..fixer_util import Comma, Name, Call
class FixExec(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
exec_stmt< 'exec' a=any 'in' b=any [',' c=any] >
diff --git a/Lib/lib2to3/fixes/fix_execfile.py b/Lib/lib2to3/fixes/fix_execfile.py
index 38d6abc9b3..2f29d3b281 100644
--- a/Lib/lib2to3/fixes/fix_execfile.py
+++ b/Lib/lib2to3/fixes/fix_execfile.py
@@ -13,6 +13,7 @@ from ..fixer_util import (Comma, Name, Call, LParen, RParen, Dot, Node,
class FixExecfile(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< 'execfile' trailer< '(' arglist< filename=any [',' globals=any [',' locals=any ] ] > ')' > >
diff --git a/Lib/lib2to3/fixes/fix_exitfunc.py b/Lib/lib2to3/fixes/fix_exitfunc.py
index 28d30b8f79..89fb3db533 100644
--- a/Lib/lib2to3/fixes/fix_exitfunc.py
+++ b/Lib/lib2to3/fixes/fix_exitfunc.py
@@ -9,6 +9,8 @@ from lib2to3.fixer_util import Name, Attr, Call, Comma, Newline, syms
class FixExitfunc(fixer_base.BaseFix):
+ keep_line_order = True
+ BM_compatible = True
PATTERN = """
(
diff --git a/Lib/lib2to3/fixes/fix_filter.py b/Lib/lib2to3/fixes/fix_filter.py
index 0e92b14521..18ee2ffc06 100644
--- a/Lib/lib2to3/fixes/fix_filter.py
+++ b/Lib/lib2to3/fixes/fix_filter.py
@@ -19,6 +19,7 @@ from .. import fixer_base
from ..fixer_util import Name, Call, ListComp, in_special_context
class FixFilter(fixer_base.ConditionalFix):
+ BM_compatible = True
PATTERN = """
filter_lambda=power<
diff --git a/Lib/lib2to3/fixes/fix_funcattrs.py b/Lib/lib2to3/fixes/fix_funcattrs.py
index 5d1ba8cfa8..9e45c02857 100644
--- a/Lib/lib2to3/fixes/fix_funcattrs.py
+++ b/Lib/lib2to3/fixes/fix_funcattrs.py
@@ -7,6 +7,8 @@ from ..fixer_util import Name
class FixFuncattrs(fixer_base.BaseFix):
+ BM_compatible = True
+
PATTERN = """
power< any+ trailer< '.' attr=('func_closure' | 'func_doc' | 'func_globals'
| 'func_name' | 'func_defaults' | 'func_code'
diff --git a/Lib/lib2to3/fixes/fix_future.py b/Lib/lib2to3/fixes/fix_future.py
index 861e13c62c..fbcb86af07 100644
--- a/Lib/lib2to3/fixes/fix_future.py
+++ b/Lib/lib2to3/fixes/fix_future.py
@@ -9,6 +9,8 @@ from .. import fixer_base
from ..fixer_util import BlankLine
class FixFuture(fixer_base.BaseFix):
+ BM_compatible = True
+
PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
# This should be run last -- some things check for the import
diff --git a/Lib/lib2to3/fixes/fix_getcwdu.py b/Lib/lib2to3/fixes/fix_getcwdu.py
index a5b5aa3778..82233c8993 100644
--- a/Lib/lib2to3/fixes/fix_getcwdu.py
+++ b/Lib/lib2to3/fixes/fix_getcwdu.py
@@ -8,6 +8,7 @@ from .. import fixer_base
from ..fixer_util import Name
class FixGetcwdu(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< 'os' trailer< dot='.' name='getcwdu' > any* >
diff --git a/Lib/lib2to3/fixes/fix_has_key.py b/Lib/lib2to3/fixes/fix_has_key.py
index 0915a363bd..bead4cb51c 100644
--- a/Lib/lib2to3/fixes/fix_has_key.py
+++ b/Lib/lib2to3/fixes/fix_has_key.py
@@ -37,6 +37,7 @@ from ..fixer_util import Name, parenthesize
class FixHasKey(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
anchor=power<
diff --git a/Lib/lib2to3/fixes/fix_idioms.py b/Lib/lib2to3/fixes/fix_idioms.py
index c07b77e55a..37b6eefa51 100644
--- a/Lib/lib2to3/fixes/fix_idioms.py
+++ b/Lib/lib2to3/fixes/fix_idioms.py
@@ -35,7 +35,6 @@ CMP = "(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)"
TYPE = "power< 'type' trailer< '(' x=any ')' > >"
class FixIdioms(fixer_base.BaseFix):
-
explicit = True # The user must ask for this fixer
PATTERN = r"""
diff --git a/Lib/lib2to3/fixes/fix_import.py b/Lib/lib2to3/fixes/fix_import.py
index d35fa0caf8..201e811e61 100644
--- a/Lib/lib2to3/fixes/fix_import.py
+++ b/Lib/lib2to3/fixes/fix_import.py
@@ -36,6 +36,7 @@ def traverse_imports(names):
class FixImport(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
import_from< 'from' imp=any 'import' ['('] any [')'] >
diff --git a/Lib/lib2to3/fixes/fix_imports.py b/Lib/lib2to3/fixes/fix_imports.py
index e1ad667f7b..93c9e6787b 100644
--- a/Lib/lib2to3/fixes/fix_imports.py
+++ b/Lib/lib2to3/fixes/fix_imports.py
@@ -84,6 +84,8 @@ def build_pattern(mapping=MAPPING):
class FixImports(fixer_base.BaseFix):
+ BM_compatible = True
+ keep_line_order = True
# This is overridden in fix_imports2.
mapping = MAPPING
diff --git a/Lib/lib2to3/fixes/fix_input.py b/Lib/lib2to3/fixes/fix_input.py
index 291cadf220..fbf4c72f5c 100644
--- a/Lib/lib2to3/fixes/fix_input.py
+++ b/Lib/lib2to3/fixes/fix_input.py
@@ -11,7 +11,7 @@ context = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >")
class FixInput(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = """
power< 'input' args=trailer< '(' [any] ')' > >
"""
diff --git a/Lib/lib2to3/fixes/fix_intern.py b/Lib/lib2to3/fixes/fix_intern.py
index 67f98efbed..e7bb5052b4 100644
--- a/Lib/lib2to3/fixes/fix_intern.py
+++ b/Lib/lib2to3/fixes/fix_intern.py
@@ -12,6 +12,8 @@ from ..fixer_util import Name, Attr, touch_import
class FixIntern(fixer_base.BaseFix):
+ BM_compatible = True
+ order = "pre"
PATTERN = """
power< 'intern'
diff --git a/Lib/lib2to3/fixes/fix_isinstance.py b/Lib/lib2to3/fixes/fix_isinstance.py
index c720a837e2..4b04c8fd0c 100644
--- a/Lib/lib2to3/fixes/fix_isinstance.py
+++ b/Lib/lib2to3/fixes/fix_isinstance.py
@@ -14,7 +14,7 @@ from ..fixer_util import token
class FixIsinstance(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = """
power<
'isinstance'
diff --git a/Lib/lib2to3/fixes/fix_itertools.py b/Lib/lib2to3/fixes/fix_itertools.py
index 77b3a015f2..5391a37b25 100644
--- a/Lib/lib2to3/fixes/fix_itertools.py
+++ b/Lib/lib2to3/fixes/fix_itertools.py
@@ -12,6 +12,7 @@ from .. import fixer_base
from ..fixer_util import Name
class FixItertools(fixer_base.BaseFix):
+ BM_compatible = True
it_funcs = "('imap'|'ifilter'|'izip'|'ifilterfalse')"
PATTERN = """
power< it='itertools'
diff --git a/Lib/lib2to3/fixes/fix_itertools_imports.py b/Lib/lib2to3/fixes/fix_itertools_imports.py
index 72f4fe4044..c1deb038e9 100644
--- a/Lib/lib2to3/fixes/fix_itertools_imports.py
+++ b/Lib/lib2to3/fixes/fix_itertools_imports.py
@@ -6,6 +6,7 @@ from lib2to3.fixer_util import BlankLine, syms, token
class FixItertoolsImports(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
import_from< 'from' 'itertools' 'import' imports=any >
""" %(locals())
diff --git a/Lib/lib2to3/fixes/fix_long.py b/Lib/lib2to3/fixes/fix_long.py
index 6f3661cbab..5dddde0d08 100644
--- a/Lib/lib2to3/fixes/fix_long.py
+++ b/Lib/lib2to3/fixes/fix_long.py
@@ -10,7 +10,7 @@ from lib2to3.fixer_util import is_probably_builtin
class FixLong(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = "'long'"
def transform(self, node, results):
diff --git a/Lib/lib2to3/fixes/fix_map.py b/Lib/lib2to3/fixes/fix_map.py
index 6d269573ad..7a7d0dbc66 100644
--- a/Lib/lib2to3/fixes/fix_map.py
+++ b/Lib/lib2to3/fixes/fix_map.py
@@ -26,6 +26,7 @@ from ..fixer_util import Name, Call, ListComp, in_special_context
from ..pygram import python_symbols as syms
class FixMap(fixer_base.ConditionalFix):
+ BM_compatible = True
PATTERN = """
map_none=power<
diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py
index 789cb168bb..f403fd6d53 100644
--- a/Lib/lib2to3/fixes/fix_metaclass.py
+++ b/Lib/lib2to3/fixes/fix_metaclass.py
@@ -143,6 +143,7 @@ def fixup_indent(suite):
class FixMetaclass(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
classdef<any*>
diff --git a/Lib/lib2to3/fixes/fix_methodattrs.py b/Lib/lib2to3/fixes/fix_methodattrs.py
index 5e94a9c526..f3c1ecfec1 100644
--- a/Lib/lib2to3/fixes/fix_methodattrs.py
+++ b/Lib/lib2to3/fixes/fix_methodattrs.py
@@ -13,6 +13,7 @@ MAP = {
}
class FixMethodattrs(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* >
"""
diff --git a/Lib/lib2to3/fixes/fix_next.py b/Lib/lib2to3/fixes/fix_next.py
index 9514798f4c..f021a9bd70 100644
--- a/Lib/lib2to3/fixes/fix_next.py
+++ b/Lib/lib2to3/fixes/fix_next.py
@@ -15,6 +15,7 @@ bind_warning = "Calls to builtin next() possibly shadowed by global binding"
class FixNext(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< base=any+ trailer< '.' attr='next' > trailer< '(' ')' > >
|
diff --git a/Lib/lib2to3/fixes/fix_nonzero.py b/Lib/lib2to3/fixes/fix_nonzero.py
index 17be377013..ba83478f81 100644
--- a/Lib/lib2to3/fixes/fix_nonzero.py
+++ b/Lib/lib2to3/fixes/fix_nonzero.py
@@ -6,6 +6,7 @@ from .. import fixer_base
from ..fixer_util import Name, syms
class FixNonzero(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
classdef< 'class' any+ ':'
suite< any*
diff --git a/Lib/lib2to3/fixes/fix_operator.py b/Lib/lib2to3/fixes/fix_operator.py
index da3d579ae2..7bf2c0dd22 100644
--- a/Lib/lib2to3/fixes/fix_operator.py
+++ b/Lib/lib2to3/fixes/fix_operator.py
@@ -14,7 +14,16 @@ from lib2to3 import fixer_base
from lib2to3.fixer_util import Call, Name, String, touch_import
+def invocation(s):
+ def dec(f):
+ f.invocation = s
+ return f
+ return dec
+
+
class FixOperator(fixer_base.BaseFix):
+ BM_compatible = True
+ order = "pre"
methods = """
method=('isCallable'|'sequenceIncludes'
@@ -34,34 +43,34 @@ class FixOperator(fixer_base.BaseFix):
if method is not None:
return method(node, results)
+ @invocation("operator.contains(%s)")
def _sequenceIncludes(self, node, results):
- """operator.contains(%s)"""
return self._handle_rename(node, results, u"contains")
+ @invocation("hasattr(%s, '__call__')")
def _isCallable(self, node, results):
- """hasattr(%s, '__call__')"""
obj = results["obj"]
args = [obj.clone(), String(u", "), String(u"'__call__'")]
return Call(Name(u"hasattr"), args, prefix=node.prefix)
+ @invocation("operator.mul(%s)")
def _repeat(self, node, results):
- """operator.mul(%s)"""
return self._handle_rename(node, results, u"mul")
+ @invocation("operator.imul(%s)")
def _irepeat(self, node, results):
- """operator.imul(%s)"""
return self._handle_rename(node, results, u"imul")
+ @invocation("isinstance(%s, collections.Sequence)")
def _isSequenceType(self, node, results):
- """isinstance(%s, collections.Sequence)"""
return self._handle_type2abc(node, results, u"collections", u"Sequence")
+ @invocation("isinstance(%s, collections.Mapping)")
def _isMappingType(self, node, results):
- """isinstance(%s, collections.Mapping)"""
return self._handle_type2abc(node, results, u"collections", u"Mapping")
+ @invocation("isinstance(%s, numbers.Number)")
def _isNumberType(self, node, results):
- """isinstance(%s, numbers.Number)"""
return self._handle_type2abc(node, results, u"numbers", u"Number")
def _handle_rename(self, node, results, name):
@@ -82,6 +91,6 @@ class FixOperator(fixer_base.BaseFix):
return method
else:
sub = (unicode(results["obj"]),)
- invocation_str = unicode(method.__doc__) % sub
+ invocation_str = unicode(method.invocation) % sub
self.warning(node, u"You should use '%s' here." % invocation_str)
return None
diff --git a/Lib/lib2to3/fixes/fix_paren.py b/Lib/lib2to3/fixes/fix_paren.py
index eeb0d4070a..8650cd9078 100644
--- a/Lib/lib2to3/fixes/fix_paren.py
+++ b/Lib/lib2to3/fixes/fix_paren.py
@@ -10,6 +10,8 @@ from ..fixer_util import LParen, RParen
# XXX This doesn't support nested for loops like [x for x in 1, 2 for x in 1, 2]
class FixParen(fixer_base.BaseFix):
+ BM_compatible = True
+
PATTERN = """
atom< ('[' | '(')
(listmaker< any
diff --git a/Lib/lib2to3/fixes/fix_print.py b/Lib/lib2to3/fixes/fix_print.py
index 6cad8ce59a..98786b3ecd 100644
--- a/Lib/lib2to3/fixes/fix_print.py
+++ b/Lib/lib2to3/fixes/fix_print.py
@@ -28,6 +28,8 @@ parend_expr = patcomp.compile_pattern(
class FixPrint(fixer_base.BaseFix):
+ BM_compatible = True
+
PATTERN = """
simple_stmt< any* bare='print' any* > | print_stmt
"""
diff --git a/Lib/lib2to3/fixes/fix_raise.py b/Lib/lib2to3/fixes/fix_raise.py
index 24e123c730..b958ba0129 100644
--- a/Lib/lib2to3/fixes/fix_raise.py
+++ b/Lib/lib2to3/fixes/fix_raise.py
@@ -4,6 +4,7 @@ raise -> raise
raise E -> raise E
raise E, V -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
+raise E, None, T -> raise E.with_traceback(T)
raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T -> warns about string exceptions
@@ -29,6 +30,7 @@ from ..fixer_util import Name, Call, Attr, ArgList, is_tuple
class FixRaise(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] >
"""
@@ -37,8 +39,9 @@ class FixRaise(fixer_base.BaseFix):
syms = self.syms
exc = results["exc"].clone()
- if exc.type is token.STRING:
- self.cannot_convert(node, "Python 3 does not support string exceptions")
+ if exc.type == token.STRING:
+ msg = "Python 3 does not support string exceptions"
+ self.cannot_convert(node, msg)
return
# Python 2 supports
@@ -52,7 +55,7 @@ class FixRaise(fixer_base.BaseFix):
# exc.children[1:-1] is the unparenthesized tuple
# exc.children[1].children[0] is the first element of the tuple
exc = exc.children[1].children[0].clone()
- exc.prefix = " "
+ exc.prefix = u" "
if "val" not in results:
# One-argument raise
@@ -71,7 +74,12 @@ class FixRaise(fixer_base.BaseFix):
tb = results["tb"].clone()
tb.prefix = u""
- e = Call(exc, args)
+ e = exc
+ # If there's a traceback and None is passed as the value, then don't
+ # add a call, since the user probably just wants to add a
+ # traceback. See issue #9661.
+ if val.type != token.NAME or val.value != u"None":
+ e = Call(exc, args)
with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb)
new.prefix = node.prefix
diff --git a/Lib/lib2to3/fixes/fix_raw_input.py b/Lib/lib2to3/fixes/fix_raw_input.py
index ba045d6341..3a73b81864 100644
--- a/Lib/lib2to3/fixes/fix_raw_input.py
+++ b/Lib/lib2to3/fixes/fix_raw_input.py
@@ -7,6 +7,7 @@ from ..fixer_util import Name
class FixRawInput(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< name='raw_input' trailer< '(' [any] ')' > any* >
"""
diff --git a/Lib/lib2to3/fixes/fix_reduce.py b/Lib/lib2to3/fixes/fix_reduce.py
index 194866d6a0..6bd785c1cd 100644
--- a/Lib/lib2to3/fixes/fix_reduce.py
+++ b/Lib/lib2to3/fixes/fix_reduce.py
@@ -14,6 +14,9 @@ from lib2to3.fixer_util import touch_import
class FixReduce(fixer_base.BaseFix):
+ BM_compatible = True
+ order = "pre"
+
PATTERN = """
power< 'reduce'
trailer< '('
diff --git a/Lib/lib2to3/fixes/fix_renames.py b/Lib/lib2to3/fixes/fix_renames.py
index a45345a981..4bcce8c4eb 100644
--- a/Lib/lib2to3/fixes/fix_renames.py
+++ b/Lib/lib2to3/fixes/fix_renames.py
@@ -40,6 +40,7 @@ def build_pattern():
class FixRenames(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = "|".join(build_pattern())
order = "pre" # Pre-order tree traversal
diff --git a/Lib/lib2to3/fixes/fix_repr.py b/Lib/lib2to3/fixes/fix_repr.py
index 4b37e73259..f34365647f 100644
--- a/Lib/lib2to3/fixes/fix_repr.py
+++ b/Lib/lib2to3/fixes/fix_repr.py
@@ -10,6 +10,7 @@ from ..fixer_util import Call, Name, parenthesize
class FixRepr(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
atom < '`' expr=any '`' >
"""
diff --git a/Lib/lib2to3/fixes/fix_set_literal.py b/Lib/lib2to3/fixes/fix_set_literal.py
index cfc522cb46..d3d38ec4e0 100644
--- a/Lib/lib2to3/fixes/fix_set_literal.py
+++ b/Lib/lib2to3/fixes/fix_set_literal.py
@@ -11,6 +11,7 @@ from lib2to3.fixer_util import token, syms
class FixSetLiteral(fixer_base.BaseFix):
+ BM_compatible = True
explicit = True
PATTERN = """power< 'set' trailer< '('
diff --git a/Lib/lib2to3/fixes/fix_standarderror.py b/Lib/lib2to3/fixes/fix_standarderror.py
index a5789ba55b..6cad51116d 100644
--- a/Lib/lib2to3/fixes/fix_standarderror.py
+++ b/Lib/lib2to3/fixes/fix_standarderror.py
@@ -9,7 +9,7 @@ from ..fixer_util import Name
class FixStandarderror(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = """
'StandardError'
"""
diff --git a/Lib/lib2to3/fixes/fix_sys_exc.py b/Lib/lib2to3/fixes/fix_sys_exc.py
index 348929bb6e..2ecca2b535 100644
--- a/Lib/lib2to3/fixes/fix_sys_exc.py
+++ b/Lib/lib2to3/fixes/fix_sys_exc.py
@@ -14,6 +14,7 @@ from ..fixer_util import Attr, Call, Name, Number, Subscript, Node, syms
class FixSysExc(fixer_base.BaseFix):
# This order matches the ordering of sys.exc_info().
exc_info = [u"exc_type", u"exc_value", u"exc_traceback"]
+ BM_compatible = True
PATTERN = """
power< 'sys' trailer< dot='.' attribute=(%s) > >
""" % '|'.join("'%s'" % e for e in exc_info)
diff --git a/Lib/lib2to3/fixes/fix_throw.py b/Lib/lib2to3/fixes/fix_throw.py
index 63271cf1d3..1468d89a45 100644
--- a/Lib/lib2to3/fixes/fix_throw.py
+++ b/Lib/lib2to3/fixes/fix_throw.py
@@ -14,7 +14,7 @@ from .. import fixer_base
from ..fixer_util import Name, Call, ArgList, Attr, is_tuple
class FixThrow(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = """
power< any trailer< '.' 'throw' >
trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' >
diff --git a/Lib/lib2to3/fixes/fix_tuple_params.py b/Lib/lib2to3/fixes/fix_tuple_params.py
index 647eec0cfc..6361717dc5 100644
--- a/Lib/lib2to3/fixes/fix_tuple_params.py
+++ b/Lib/lib2to3/fixes/fix_tuple_params.py
@@ -29,6 +29,10 @@ def is_docstring(stmt):
stmt.children[0].type == token.STRING
class FixTupleParams(fixer_base.BaseFix):
+ run_order = 4 #use a lower order since lambda is part of other
+ #patterns
+ BM_compatible = True
+
PATTERN = """
funcdef< 'def' any parameters< '(' args=any ')' >
['->' any] ':' suite=any+ >
diff --git a/Lib/lib2to3/fixes/fix_types.py b/Lib/lib2to3/fixes/fix_types.py
index 2fbbab8792..fc9d495927 100644
--- a/Lib/lib2to3/fixes/fix_types.py
+++ b/Lib/lib2to3/fixes/fix_types.py
@@ -52,7 +52,7 @@ _TYPE_MAPPING = {
_pats = ["power< 'types' trailer< '.' name='%s' > >" % t for t in _TYPE_MAPPING]
class FixTypes(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = '|'.join(_pats)
def transform(self, node, results):
diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py
index cd3b89cb17..6c89576540 100644
--- a/Lib/lib2to3/fixes/fix_unicode.py
+++ b/Lib/lib2to3/fixes/fix_unicode.py
@@ -10,7 +10,7 @@ _mapping = {u"unichr" : u"chr", u"unicode" : u"str"}
_literal_re = re.compile(ur"[uU][rR]?[\'\"]")
class FixUnicode(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = "STRING | 'unicode' | 'unichr'"
def transform(self, node, results):
diff --git a/Lib/lib2to3/fixes/fix_urllib.py b/Lib/lib2to3/fixes/fix_urllib.py
index 1b3ef3f8d9..f91fe2a035 100644
--- a/Lib/lib2to3/fixes/fix_urllib.py
+++ b/Lib/lib2to3/fixes/fix_urllib.py
@@ -8,7 +8,7 @@
from lib2to3.fixes.fix_imports import alternates, FixImports
from lib2to3 import fixer_base
from lib2to3.fixer_util import (Name, Comma, FromImport, Newline,
- find_indentation)
+ find_indentation, Node, syms)
MAPPING = {"urllib": [
("urllib.request",
@@ -121,26 +121,37 @@ class FixUrllib(FixImports):
mod_dict = {}
members = results["members"]
for member in members:
- member = member.value
# we only care about the actual members
- if member != u",":
+ if member.type == syms.import_as_name:
+ as_name = member.children[2].value
+ member_name = member.children[0].value
+ else:
+ member_name = member.value
+ as_name = None
+ if member_name != u",":
for change in MAPPING[mod_member.value]:
- if member in change[1]:
- if change[0] in mod_dict:
- mod_dict[change[0]].append(member)
- else:
- mod_dict[change[0]] = [member]
+ if member_name in change[1]:
+ if change[0] not in mod_dict:
modules.append(change[0])
+ mod_dict.setdefault(change[0], []).append(member)
new_nodes = []
indentation = find_indentation(node)
first = True
+ def handle_name(name, prefix):
+ if name.type == syms.import_as_name:
+ kids = [Name(name.children[0].value, prefix=prefix),
+ name.children[1].clone(),
+ name.children[2].clone()]
+ return [Node(syms.import_as_name, kids)]
+ return [Name(name.value, prefix=prefix)]
for module in modules:
elts = mod_dict[module]
names = []
for elt in elts[:-1]:
- names.extend([Name(elt, prefix=pref), Comma()])
- names.append(Name(elts[-1], prefix=pref))
+ names.extend(handle_name(elt, pref))
+ names.append(Comma())
+ names.extend(handle_name(elts[-1], pref))
new = FromImport(module, names)
if not first or node.parent.prefix.endswith(indentation):
new.prefix = indentation
diff --git a/Lib/lib2to3/fixes/fix_xrange.py b/Lib/lib2to3/fixes/fix_xrange.py
index 2eb106504e..f1436724b4 100644
--- a/Lib/lib2to3/fixes/fix_xrange.py
+++ b/Lib/lib2to3/fixes/fix_xrange.py
@@ -10,7 +10,7 @@ from .. import patcomp
class FixXrange(fixer_base.BaseFix):
-
+ BM_compatible = True
PATTERN = """
power<
(name='range'|name='xrange') trailer< '(' args=any ')' >
diff --git a/Lib/lib2to3/fixes/fix_xreadlines.py b/Lib/lib2to3/fixes/fix_xreadlines.py
index ee4b356d3d..f50b9a2755 100644
--- a/Lib/lib2to3/fixes/fix_xreadlines.py
+++ b/Lib/lib2to3/fixes/fix_xreadlines.py
@@ -9,6 +9,7 @@ from ..fixer_util import Name
class FixXreadlines(fixer_base.BaseFix):
+ BM_compatible = True
PATTERN = """
power< call=any+ trailer< '.' 'xreadlines' > trailer< '(' ')' > >
|
diff --git a/Lib/lib2to3/fixes/fix_zip.py b/Lib/lib2to3/fixes/fix_zip.py
index 6736a7edc2..c5d7b66d67 100644
--- a/Lib/lib2to3/fixes/fix_zip.py
+++ b/Lib/lib2to3/fixes/fix_zip.py
@@ -13,6 +13,7 @@ from ..fixer_util import Name, Call, in_special_context
class FixZip(fixer_base.ConditionalFix):
+ BM_compatible = True
PATTERN = """
power< 'zip' args=trailer< '(' [any] ')' >
>