def test_union_with_similar_nested_generic_types():
    """Previously this failed due to an edge case where Strawberry would choose AContainer
    as the resolved type for container_b due to the inability to exactly match the
    nested generic `Container.items`.
    """
    T = TypeVar("T")

    @strawberry.type
    class Container(Generic[T]):
        items: list[T]

    @strawberry.type
    class A:
        a: str

    @strawberry.type
    class B:
        b: int

    @strawberry.type
    class Query:
        @strawberry.field
        def container_a(self) -> Union[Container[A], A]:
            return Container(items=[A(a="hello")])

        @strawberry.field
        def container_b(self) -> Union[Container[B], B]:
            return Container(items=[B(b=3)])

    schema = strawberry.Schema(query=Query)

    query = """
     {
        containerA {
            __typename
            ... on AContainer {
                items {
                    a
                }
            }
            ... on A {
                a
            }
        }
    }
    """

    result = schema.execute_sync(query)

    assert result.data["containerA"]["items"][0]["a"] == "hello"

    query = """
     {
        containerB {
            __typename
            ... on BContainer {
                items {
                    b
                }
            }
            ... on B {
                b
            }
        }
    }
    """

    result = schema.execute_sync(query)

    assert result.data["containerB"]["items"][0]["b"] == 3
Previously this failed due to an edge case where Strawberry would choose AContainer
    as the resolved type for container_b due to the inability to exactly match the
    nested generic `Container.items`.
    
tests/schema/test_union.py