Example #1
0
 def _postprocess_pyi(self, ast):
     """Apply all the PYI transformations we need."""
     package_name = module_utils.get_package_name(ast.name, ast.is_package)
     if package_name:
         ast = ast.Visit(visitors.QualifyRelativeNames(package_name))
     ast = ast.Visit(
         visitors.LookupBuiltins(self.builtins, full_names=False))
     ast = ast.Visit(visitors.ExpandCompatibleBuiltins(self.builtins))
     dependencies = self._collect_ast_dependencies(ast)
     if dependencies:
         self._load_ast_dependencies(dependencies, ast)
         ast = self._resolve_external_types(ast)
     ast = ast.Visit(visitors.LookupLocalTypes())
     return ast
Example #2
0
 def testQualifyRelativeNames(self):
     src = "from . import foo"
     ast = self.Parse(src).Visit(visitors.QualifyRelativeNames("package"))
     _, module = ast.Lookup("foo")  # Alias(foo, Module)
     self.assertEqual(module.module_name, "package.foo")