def union(
    name: str,
    types: Optional[Collection[type[Any]]] = None,
    *,
    description: Optional[str] = None,
    directives: Iterable[object] = (),
) -> StrawberryUnion:
    """Creates a new named Union type.

    Args:
        name: The GraphQL name of the Union type.
        types: The types that the Union can be.
            (Deprecated, use `Annotated[U, strawberry.union("Name")]` instead)
        description: The  GraphQL description of the Union type.
        directives: The directives to attach to the Union type.

    Example usages:

    ```python
    import strawberry
    from typing import Annotated

    @strawberry.type
    class A: ...

    @strawberry.type
    class B: ...

    MyUnion = Annotated[A | B, strawberry.union("Name")]
    """
    if types is None:
        union = StrawberryUnion(
            name=name,
            description=description,
            directives=directives,
        )

        if should_use_rich_exceptions():
            frame = sys._getframe(1)

            union._source_file = frame.f_code.co_filename
            union._source_line = frame.f_lineno

        return union

    warnings.warn(
        (
            "Passing types to `strawberry.union` is deprecated. Please use "
            f'{name} = Annotated[Union[A, B], strawberry.union("{name}")] instead'
        ),
        DeprecationWarning,
        stacklevel=2,
    )

    # Validate types
    if not types:
        raise TypeError("No types passed to `union`")

    for type_ in types:
        # Due to TypeVars, Annotations, LazyTypes, etc., this does not perfectly detect
        # issues. This check also occurs in the Schema conversion stage as a backup.
        if not StrawberryUnion.is_valid_union_type(type_):
            raise InvalidUnionTypeError(union_name=name, invalid_type=type_)

    return StrawberryUnion(
        name=name,
        type_annotations=tuple(StrawberryAnnotation(type_) for type_ in types),
        description=description,
        directives=directives,
    )
Creates a new named Union type.

    Args:
        name: The GraphQL name of the Union type.
        types: The types that the Union can be.
            (Deprecated, use `Annotated[U, strawberry.union("Name")]` instead)
        description: The  GraphQL description of the Union type.
        directives: The directives to attach to the Union type.

    Example usages:

    ```python
    import strawberry
    from typing import Annotated

    @strawberry.type
    class A: ...

    @strawberry.type
    class B: ...

    MyUnion = Annotated[A | B, strawberry.union("Name")]
    
strawberry/types/union.py