Converts pyi files to pickled asts and saves them to disk. Used to speed up module importing. This is done by loading the ast and serializing it to disk. Further users only need to read the serialized data from disk, which is faster to digest than a pyi file.
Class |
|
Visitor to find class and function types. |
Class |
|
The data pickled to disk to save an ast. |
Class |
|
Undocumented |
Class |
|
Visitor to undo module aliases in late types. |
Exception |
|
If a dependency can't be restored in the current state. |
Function |
|
Verify that serializable_ast has the name module_name, or repair it. |
Function |
|
Fill in local references. |
Function |
|
Prepare an ast as if it was parsed and loaded. |
Function |
|
Postprocess a pickled ast. |
Function |
|
Loads and stores an ast to disk. |
Function |
|
Parse the source code into a pickle-able ast. |
Function | _ |
Fills .cls references in serializable_ast.ast with ones from module_map. |
Verify that serializable_ast has the name module_name, or repair it. Args: ast: An instance of SerializableAst. module_name: The name under which ast.ast should be loaded. fix: If this function should repair the wrong name. Returns: The updated SerializableAst.
Prepare an ast as if it was parsed and loaded. External dependencies will not be resolved, as the ast generated by this method is supposed to be exported. Args: module_name: The module_name as a string for the returned ast. ast: pytd.TypeDeclUnit, is only used if src is None. loader: A load_pytd.Loader instance. Returns: A pytd.TypeDeclUnit representing the supplied AST as it would look after being written to a file and parsed.
Postprocess a pickled ast. Postprocessing will either just fill the ClassType references from module_map or if module_name changed between pickling and loading rename the module internal references to the new module_name. Renaming is more expensive than filling references, as the whole AST needs to be rebuild. Args: serializable_ast: A SerializableAst instance. module_map: Used to resolve ClassType.cls links to already loaded modules. The loaded module will be added to the dict. Returns: A pytd.TypeDeclUnit, this is either the input raw_ast with the references set or a newly created AST with the new module_name and the references set. Raises: AssertionError: If module_name is already in module_map, which means that module_name is already loaded. UnrestorableDependencyError: If no concrete module exists in module_map for one of the references from the pickled ast.
Loads and stores an ast to disk. Args: ast: The pytd.TypeDeclUnit to save to disk. src_path: Optionally, the filepath of the original source file. metadata: A list of arbitrary string-encoded metadata. Returns: The SerializableAst derived from `ast`.
Fills .cls references in serializable_ast.ast with ones from module_map. Already filled references are not changed. References to the module self._name are not filled. Setting self_name=None will fill all references. Args: serializable_ast: A SerializableAst instance. module_map: Used to resolve ClassType.cls links to already loaded modules. The loaded module will be added to the dict. self_name: A string representation of a module which should not be resolved, for example: "foo.bar.module1" or None to resolve all modules. Returns: A SerializableAst with an updated .ast. .class_type_nodes is set to None if any of the Nodes needed to be regenerated.