Commits

Benjamin Peterson committed 22038ab

#7375 fix nested transformations in fix_urllib

Comments (0)

Files changed (2)

lib2to3/fixes/fix_urllib.py

             yield """import_name< 'import'
                                   dotted_as_name< module_as=%r 'as' any > >
                   """ % old_module
-            yield """power< module_dot=%r trailer< '.' member=%s > any* >
+            # bare_with_attr has a special significance for FixImports.match().
+            yield """power< bare_with_attr=%r trailer< '.' member=%s > any* >
                   """ % (old_module, members)
 
 
 
     def transform_dot(self, node, results):
         """Transform for calls to module members in code."""
-        module_dot = results.get('module_dot')
+        module_dot = results.get('bare_with_attr')
         member = results.get('member')
-        # this may be a list of length one, or just a node
+        new_name = None
         if isinstance(member, list):
             member = member[0]
-        new_name = None
         for change in MAPPING[module_dot.value]:
             if member.value in change[1]:
                 new_name = change[0]
             self.transform_import(node, results)
         elif results.get('mod_member'):
             self.transform_member(node, results)
-        elif results.get('module_dot'):
+        elif results.get('bare_with_attr'):
             self.transform_dot(node, results)
         # Renaming and star imports are not supported for these modules.
         elif results.get('module_star'):

lib2to3/tests/test_fixers.py

         for old, changes in self.modules.items():
             for new, members in changes:
                 for member in members:
+                    new_import = ", ".join([n for (n, mems)
+                                            in self.modules[old]])
                     b = """
                         import %s
                         foo(%s.%s)
                     a = """
                         import %s
                         foo(%s.%s)
-                        """ % (", ".join([n for (n, mems)
-                                           in self.modules[old]]),
-                                         new, member)
+                        """ % (new_import, new, member)
+                    self.check(b, a)
+                    b = """
+                        import %s
+                        %s.%s(%s.%s)
+                        """ % (old, old, member, old, member)
+                    a = """
+                        import %s
+                        %s.%s(%s.%s)
+                        """ % (new_import, new, member, new, member)
                     self.check(b, a)