Skip to content

migrate_move_annotation

Source code in library_analyzer/processing/migration/annotations/_migrate_move_annotation.py
def migrate_move_annotation(
    move_annotation: MoveAnnotation, mapping: Mapping
) -> list[AbstractAnnotation]:
    move_annotation = deepcopy(move_annotation)
    authors = move_annotation.authors
    authors.append(migration_author)
    move_annotation.authors = authors

    if isinstance(mapping, (ManyToOneMapping, OneToOneMapping)):
        element = mapping.get_apiv2_elements()[0]
        if isinstance(element, (Attribute, Result)):
            return []
        if not is_moveable(element):
            return [
                TodoAnnotation(
                    element.id,
                    authors,
                    move_annotation.reviewers,
                    move_annotation.comment,
                    EnumReviewResult.NONE,
                    get_migration_text(
                        move_annotation, mapping, for_todo_annotation=True
                    ),
                )
            ]
        move_annotation.target = element.id
        return [move_annotation]

    annotated_apiv1_element = get_annotated_api_element(
        move_annotation, mapping.get_apiv1_elements()
    )
    if annotated_apiv1_element is None:
        return []

    move_annotations: list[AbstractAnnotation] = []
    for element in mapping.get_apiv2_elements():
        if (
            isinstance(element, type(annotated_apiv1_element))
            and is_moveable(element)
            and not isinstance(element, (Attribute, Result))
        ):
            move_annotations.append(
                MoveAnnotation(
                    element.id,
                    authors,
                    move_annotation.reviewers,
                    move_annotation.comment,
                    EnumReviewResult.NONE,
                    move_annotation.destination,
                )
            )
        elif not isinstance(element, (Attribute, Result)):
            move_annotations.append(
                TodoAnnotation(
                    element.id,
                    authors,
                    move_annotation.reviewers,
                    move_annotation.comment,
                    EnumReviewResult.NONE,
                    get_migration_text(
                        move_annotation, mapping, for_todo_annotation=True
                    ),
                )
            )
    return move_annotations