mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Merged revisions 67183,67191,67371 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67183 | benjamin.peterson | 2008-11-11 04:51:33 +0100 (Di, 11 Nov 2008) | 1 line handle 'import x as y' in fix_imports; this still needs more work... ........ r67191 | benjamin.peterson | 2008-11-12 00:24:51 +0100 (Mi, 12 Nov 2008) | 1 line super() is good ........ r67371 | benjamin.peterson | 2008-11-24 23:02:00 +0100 (Mo, 24 Nov 2008) | 1 line don't blow up in the metaclass fixer when assignments in the class statement aren't simple ........
This commit is contained in:
		
							parent
							
								
									2b5d6ebfe5
								
							
						
					
					
						commit
						64903f9ed9
					
				
					 3 changed files with 31 additions and 9 deletions
				
			
		| 
						 | 
					@ -13,7 +13,7 @@ Becomes:
 | 
				
			||||||
# Local imports
 | 
					# Local imports
 | 
				
			||||||
from .. import fixer_base
 | 
					from .. import fixer_base
 | 
				
			||||||
from os.path import dirname, join, exists, pathsep
 | 
					from os.path import dirname, join, exists, pathsep
 | 
				
			||||||
from ..fixer_util import FromImport
 | 
					from ..fixer_util import FromImport, syms
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FixImport(fixer_base.BaseFix):
 | 
					class FixImport(fixer_base.BaseFix):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,11 +26,14 @@ class FixImport(fixer_base.BaseFix):
 | 
				
			||||||
    def transform(self, node, results):
 | 
					    def transform(self, node, results):
 | 
				
			||||||
        imp = results['imp']
 | 
					        imp = results['imp']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        mod_name = str(imp.children[0] if imp.type == syms.dotted_as_name \
 | 
				
			||||||
 | 
					                               else imp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if str(imp).startswith('.'):
 | 
					        if str(imp).startswith('.'):
 | 
				
			||||||
            # Already a new-style import
 | 
					            # Already a new-style import
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not probably_a_local_import(str(imp), self.filename):
 | 
					        if not probably_a_local_import(str(mod_name), self.filename):
 | 
				
			||||||
            # I guess this is a global import -- skip it!
 | 
					            # I guess this is a global import -- skip it!
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,8 +110,11 @@ def find_metas(cls_node):
 | 
				
			||||||
        if simple_node.type == syms.simple_stmt and simple_node.children:
 | 
					        if simple_node.type == syms.simple_stmt and simple_node.children:
 | 
				
			||||||
            expr_node = simple_node.children[0]
 | 
					            expr_node = simple_node.children[0]
 | 
				
			||||||
            if expr_node.type == syms.expr_stmt and expr_node.children:
 | 
					            if expr_node.type == syms.expr_stmt and expr_node.children:
 | 
				
			||||||
                leaf_node = expr_node.children[0]
 | 
					                # Check if the expr_node is a simple assignment.
 | 
				
			||||||
                if leaf_node.value == '__metaclass__':
 | 
					                left_node = expr_node.children[0]
 | 
				
			||||||
 | 
					                if isinstance(left_node, Leaf) and \
 | 
				
			||||||
 | 
					                        left_node.value == '__metaclass__':
 | 
				
			||||||
 | 
					                    # We found a assignment to __metaclass__.
 | 
				
			||||||
                    fixup_simple_stmt(node, i, simple_node)
 | 
					                    fixup_simple_stmt(node, i, simple_node)
 | 
				
			||||||
                    remove_trailing_newline(simple_node)
 | 
					                    remove_trailing_newline(simple_node)
 | 
				
			||||||
                    yield (node, i, simple_node)
 | 
					                    yield (node, i, simple_node)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2622,7 +2622,7 @@ class Test_map(FixerTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check(self, b, a):
 | 
					    def check(self, b, a):
 | 
				
			||||||
        self.unchanged("from future_builtins import map; " + b, a)
 | 
					        self.unchanged("from future_builtins import map; " + b, a)
 | 
				
			||||||
        FixerTestCase.check(self, b, a)
 | 
					        super(Test_map, self).check(b, a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_prefix_preservation(self):
 | 
					    def test_prefix_preservation(self):
 | 
				
			||||||
        b = """x =    map(   f,    'abc'   )"""
 | 
					        b = """x =    map(   f,    'abc'   )"""
 | 
				
			||||||
| 
						 | 
					@ -2729,7 +2729,7 @@ class Test_zip(FixerTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check(self, b, a):
 | 
					    def check(self, b, a):
 | 
				
			||||||
        self.unchanged("from future_builtins import zip; " + b, a)
 | 
					        self.unchanged("from future_builtins import zip; " + b, a)
 | 
				
			||||||
        FixerTestCase.check(self, b, a)
 | 
					        super(Test_zip, self).check(b, a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_zip_basic(self):
 | 
					    def test_zip_basic(self):
 | 
				
			||||||
        b = """x = zip(a, b, c)"""
 | 
					        b = """x = zip(a, b, c)"""
 | 
				
			||||||
| 
						 | 
					@ -3274,7 +3274,7 @@ class Test_import(FixerTestCase):
 | 
				
			||||||
    fixer = "import"
 | 
					    fixer = "import"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        FixerTestCase.setUp(self)
 | 
					        super(Test_import, self).setUp()
 | 
				
			||||||
        # Need to replace fix_import's exists method
 | 
					        # Need to replace fix_import's exists method
 | 
				
			||||||
        # so we can check that it's doing the right thing
 | 
					        # so we can check that it's doing the right thing
 | 
				
			||||||
        self.files_checked = []
 | 
					        self.files_checked = []
 | 
				
			||||||
| 
						 | 
					@ -3293,9 +3293,9 @@ class Test_import(FixerTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check_both(self, b, a):
 | 
					    def check_both(self, b, a):
 | 
				
			||||||
        self.always_exists = True
 | 
					        self.always_exists = True
 | 
				
			||||||
        FixerTestCase.check(self, b, a)
 | 
					        super(Test_import, self).check(b, a)
 | 
				
			||||||
        self.always_exists = False
 | 
					        self.always_exists = False
 | 
				
			||||||
        FixerTestCase.unchanged(self, b)
 | 
					        super(Test_import, self).unchanged(b)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_files_checked(self):
 | 
					    def test_files_checked(self):
 | 
				
			||||||
        def p(path):
 | 
					        def p(path):
 | 
				
			||||||
| 
						 | 
					@ -3372,6 +3372,11 @@ class Test_import(FixerTestCase):
 | 
				
			||||||
        a = "from . import foo, bar"
 | 
					        a = "from . import foo, bar"
 | 
				
			||||||
        self.check_both(b, a)
 | 
					        self.check_both(b, a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_import_as(self):
 | 
				
			||||||
 | 
					        b = "import foo as x"
 | 
				
			||||||
 | 
					        a = "from . import foo as x"
 | 
				
			||||||
 | 
					        self.check_both(b, a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_dotted_import(self):
 | 
					    def test_dotted_import(self):
 | 
				
			||||||
        b = "import foo.bar"
 | 
					        b = "import foo.bar"
 | 
				
			||||||
        a = "from . import foo.bar"
 | 
					        a = "from . import foo.bar"
 | 
				
			||||||
| 
						 | 
					@ -3766,6 +3771,17 @@ class Test_metaclass(FixerTestCase):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        self.check(b, a)
 | 
					        self.check(b, a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        b = """
 | 
				
			||||||
 | 
					        class X:
 | 
				
			||||||
 | 
					            __metaclass__ = Meta
 | 
				
			||||||
 | 
					            save.py = 23
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        a = """
 | 
				
			||||||
 | 
					        class X(metaclass=Meta):
 | 
				
			||||||
 | 
					            save.py = 23
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        self.check(b, a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Test_getcwdu(FixerTestCase):
 | 
					class Test_getcwdu(FixerTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue