Skip to content

Latest commit

 

History

History
103 lines (57 loc) · 5.63 KB

File metadata and controls

103 lines (57 loc) · 5.63 KB
graph LR
    CodeTransformationOrchestrator["CodeTransformationOrchestrator"]
    StubDataLoader["StubDataLoader"]
    StubDataRetriever["StubDataRetriever"]
    TypeNameNormalizer["TypeNameNormalizer"]
    ImportManager["ImportManager"]
    AnnotationBuilder["AnnotationBuilder"]
    AnnotationFormatter["AnnotationFormatter"]
    Python2AnnotationInserter["Python2AnnotationInserter"]
    CodeTransformationOrchestrator -- "delegates formatting tasks to" --> AnnotationFormatter
    CodeTransformationOrchestrator -- "invokes" --> Python2AnnotationInserter
    CodeTransformationOrchestrator -- "coordinates with" --> ImportManager
    CodeTransformationOrchestrator -- "relies on" --> AnnotationBuilder
    StubDataRetriever -- "loads data via" --> StubDataLoader
    StubDataRetriever -- "provides data to" --> TypeNameNormalizer
    TypeNameNormalizer -- "requests necessary imports from" --> ImportManager
    AnnotationBuilder -- "queries" --> StubDataRetriever
    AnnotationBuilder -- "prepares annotations for" --> AnnotationFormatter
Loading

CodeBoardingDemoContact

Details

The Source Code Annotator is a core subsystem within pyannotate, responsible for the "Static Code Transformation" phase. It modifies Python source files by inserting inferred type annotations directly into the code, leveraging Python's lib2to3 for Abstract Syntax Tree (AST) manipulation.

CodeTransformationOrchestrator

Manages the overall process of applying type annotations to a Python source file's Abstract Syntax Tree (AST), adapting to Python 2 or Python 3 syntax. It is the core logic driver for the code modification.

Related Classes/Methods:

StubDataLoader

Initializes and loads the raw annotation data from the JSON stub file into internal data structures, making it accessible for retrieval by other components.

Related Classes/Methods:

StubDataRetriever

Fetches specific type annotations for functions and methods from the pre-generated JSON stub data. It acts as the interface to the collected type information.

Related Classes/Methods:

TypeNameNormalizer

Iterates through and transforms type names retrieved from the stub, ensuring consistency, correctness, and proper formatting (e.g., adding typing module prefixes where required).

Related Classes/Methods:

ImportManager

Manages the addition of necessary import statements (e.g., typing) to the source file's AST based on the types being annotated. It ensures the modified code remains syntactically correct and runnable.

Related Classes/Methods:

AnnotationBuilder

Constructs the complete annotation structure for a given function or method, primarily by querying the stub data for type information and preparing it for formatting.

Related Classes/Methods:

AnnotationFormatter

Prepares and formats the annotation details into the correct string representation (e.g., -> int, : str) before they are inserted into the code's AST.

Related Classes/Methods:

Python2AnnotationInserter

Specifically handles the insertion of Python 2 style type comments (e.g., # type: (str) -> None) into the source code's AST. This component addresses backward compatibility.

Related Classes/Methods: