Skip to content

migrate_boundary_annotation

Source code in src/library_analyzer/processing/migration/annotations/_migrate_boundary_annotation.py
def migrate_boundary_annotation(origin_annotation: BoundaryAnnotation, mapping: Mapping) -> list[AbstractAnnotation]:
    annotated_apiv1_element = get_annotated_api_element(origin_annotation, mapping.get_apiv1_elements())
    if annotated_apiv1_element is None or not isinstance(annotated_apiv1_element, Parameter):
        return []

    migrated_annotations: list[AbstractAnnotation] = []
    for parameter in mapping.get_apiv2_elements():
        boundary_annotation = deepcopy(origin_annotation)
        authors = boundary_annotation.authors
        authors.append(migration_author)
        boundary_annotation.authors = authors
        if isinstance(parameter, Parameter):
            (
                parameter_expects_number,
                parameter_type_is_discrete,
            ) = _contains_number_and_is_discrete(parameter.type)
            if parameter.type is None and annotated_apiv1_element.type is not None:
                boundary_annotation.reviewResult = EnumReviewResult.UNSURE
                boundary_annotation.comment = get_migration_text(boundary_annotation, mapping)
                boundary_annotation.target = parameter.id
                migrated_annotations.append(boundary_annotation)
                continue
            if parameter_expects_number or (parameter.type is None and annotated_apiv1_element.type is None):
                if (parameter_type_is_discrete != boundary_annotation.interval.isDiscrete) and not (
                    parameter.type is None and annotated_apiv1_element.type is None
                ):
                    boundary_annotation.reviewResult = EnumReviewResult.UNSURE
                    boundary_annotation.comment = get_migration_text(boundary_annotation, mapping)
                    if parameter_expects_number:
                        boundary_annotation.interval = migrate_interval_to_fit_parameter_type(
                            boundary_annotation.interval,
                            parameter_type_is_discrete,
                        )
                boundary_annotation.target = parameter.id
                migrated_annotations.append(boundary_annotation)
                continue
        migrated_annotations.append(
            TodoAnnotation(
                parameter.id,
                authors,
                boundary_annotation.reviewers,
                boundary_annotation.comment,
                EnumReviewResult.NONE,
                get_migration_text(boundary_annotation, mapping, for_todo_annotation=True),
            ),
        )
    return migrated_annotations