Skip to content

Annotating

Typegen API

TypeHintGenerator

Bases: abc.ABC

Base class for different generation styles of type hints

apply(root)

Applies the type hint generation on the files in the root folder.

Parameters:

Name Type Description Default
root pathlib.Path

The root folder path.

required

AddImportTransformer

Bases: cst.CSTTransformer

Transforms the CST by adding ImportFrom nodes to import the modules of the type hints according to the trace data.

TypeHintTransformer

Bases: cst.CSTTransformer

Transforms the CST by adding the traced type hints without modifying the original type hints.

InlineGenerator

Bases: TypeHintGenerator

Overwrites the files by adding the traced type hints to the variables. Does not overwrite existing type hints.

RemoveAllTypeHintsTransformer

Bases: cst.CSTTransformer

Transforms the CST by removing all type hints.

EvaluationInlineGenerator

Bases: InlineGenerator

Overwrites the files by removing the existing and then adding the traced type hints.

ImportUnionTransformer

Bases: cst.CSTTransformer

Transforms the CST by adding the ImportFrom node (from typing import Union) if the corresponding code contains a union type hint.

MyPyHintTransformer

Bases: cst.CSTTransformer

Replaces the CST with the corresponding stub CST, generated using mypy.stubgen.

StubFileGenerator

Bases: TypeHintGenerator

Generates stub files using mypy.stubgen.

TraceDataFilter

Bases: abc.ABC

Base class for different trace data filters.

To implement a new filter class, inherit from this class and overwrite the abstract methods.

apply(trace_data) abstractmethod

Processes the provided trace data and returns the processed trace data and the difference between the old and new data.

Parameters:

Name Type Description Default
trace_data pd.DataFrame

The provided trace data to process.

required

Returns:

Type Description
pd.DataFrame

The processed trace data.

TraceDataFilterList

Bases: TraceDataFilter

Applies the filters in this list on the trace data in the order they were appended

append(trace_data_filter)

Appends a filter to the list.

Parameters:

Name Type Description Default
trace_data_filter TraceDataFilter

The filter to append.

required

apply(trace_data)

Chains execution of filters on the provided trace data and returns the processed trace data.

Parameters:

Name Type Description Default
trace_data pd.DataFrame

The provided trace data to process.

required

Returns:

Type Description
pd.DataFrame

The processed trace data.

DropDuplicatesFilter

Bases: TraceDataFilter

Drops all duplicates in the trace data.

MinThresholdFilter

Bases: TraceDataFilter

Drops all rows whose types appear less often than the minimum threshold.

DropTestFunctionDataFilter

Bases: TraceDataFilter

Drops all data about test functions.

DropVariablesOfMultipleTypesFilter

Bases: TraceDataFilter

Drops rows containing variables the amount of the corresponding types is higher or equal than the specified min amount.

KeepOnlyFirstFilter

Bases: TraceDataFilter

Keeps only the first row of each variable.

UnifySubTypesFilter

Bases: TraceDataFilter

Unify rows containing types in the data with their common base type.

UnionFilter

Bases: TraceDataFilter

Unify rows containing types in the data with the union of these types.

TraceDataFileCollector

Bases: DataFileCollector

Collects trace data files in a given path.

__init__()

Creates an instance of TraceDataFileCollector.

collect_data(path, include_also_files_in_subdirectories=True)

Collects the data in a given path.

Parameters:

Name Type Description Default
path pathlib.Path

The path of the folder containing the files.

required
include_also_files_in_subdirectories bool

Whether the data files in the subfolders should also be collected.

True