mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	Fix a bug where code was trying to index an int. Left over from the situation
from using str.rpartition to str.rindex. Closes Issue5213.
This commit is contained in:
		
							parent
							
								
									75a4fab6a4
								
							
						
					
					
						commit
						ac10be365e
					
				
					 2 changed files with 7 additions and 4 deletions
				
			
		| 
						 | 
					@ -15,7 +15,7 @@ def _resolve_name(name, package, level):
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        # rpartition is more "correct" and rfind is just as easy to use, but
 | 
					        # rpartition is more "correct" and rfind is just as easy to use, but
 | 
				
			||||||
        # neither are in Python 2.3.
 | 
					        # neither are in Python 2.3.
 | 
				
			||||||
        dot_rindex = package.rindex('.', level)[0]
 | 
					        dot_rindex = package.rindex('.', level)
 | 
				
			||||||
        base = package[:dot_rindex]
 | 
					        base = package[:dot_rindex]
 | 
				
			||||||
    except ValueError:
 | 
					    except ValueError:
 | 
				
			||||||
        base = package
 | 
					        base = package
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -140,11 +140,14 @@ class ImportModuleTests(unittest.TestCase):
 | 
				
			||||||
        pkg_name = 'pkg'
 | 
					        pkg_name = 'pkg'
 | 
				
			||||||
        pkg_long_name = '{0}.__init__'.format(pkg_name)
 | 
					        pkg_long_name = '{0}.__init__'.format(pkg_name)
 | 
				
			||||||
        module_name = 'mod'
 | 
					        module_name = 'mod'
 | 
				
			||||||
 | 
					        subpkg_name = '{0}.subpkg'.format(pkg_name)
 | 
				
			||||||
 | 
					        subpkg_long_name = '{0}.__init__'.format(subpkg_name)
 | 
				
			||||||
        absolute_name = '{0}.{1}'.format(pkg_name, module_name)
 | 
					        absolute_name = '{0}.{1}'.format(pkg_name, module_name)
 | 
				
			||||||
        relative_name = '.{0}'.format(module_name)
 | 
					        relative_name = '..{0}'.format(module_name)
 | 
				
			||||||
        with mock_modules(pkg_long_name, absolute_name) as mock:
 | 
					        with mock_modules(pkg_long_name, subpkg_long_name,
 | 
				
			||||||
 | 
					                            absolute_name) as mock:
 | 
				
			||||||
            with import_state(meta_path=[mock]):
 | 
					            with import_state(meta_path=[mock]):
 | 
				
			||||||
                module = importlib.import_module(relative_name, pkg_name)
 | 
					                module = importlib.import_module(relative_name, subpkg_name)
 | 
				
			||||||
                self.assertEqual(module.__name__, absolute_name)
 | 
					                self.assertEqual(module.__name__, absolute_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_absolute_import_with_package(self):
 | 
					    def test_absolute_import_with_package(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue