Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

DocumentArray is not Generic for TypeVar #1146

Closed

Description

@samsja

Context

DocumentArray is a Generic but cannot be used with TypeVar. We need to handle this case as well. We need to modify the class_getitem of AnyDocumentArray.

This don't work

from docarray import DocumentArray, BaseDocument
from typing import TypeVar, List

T = TypeVar('T', bound=BaseDocument)


def f(a: DocumentArray[T]) -> DocumentArray[T]:
    return a
Traceback (most recent call last):
  File "scratch_3.py", line 7, in <module>
    def f(a: DocumentArray[T]) -> DocumentArray[T]:
  File "docarray/docarray/array/abstract_array.py", line 38, in __class_getitem__
    if not issubclass(item, BaseDocument):
  File "/versions/3.9.10/lib/python3.9/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

whereas this work fine

def g(a: List[T]) -> List[T]:
    return a

Activity

  1. converted this from a draft issue on Feb 17, 2023
  2. agaraman0 commented on Feb 23, 2023

    @agaraman0
    Contributor

    Hey, @samsja I would like to pick up this issue.

  3. samsja commented on Feb 23, 2023

    @samsja
    MemberAuthor

    Hey @agaraman0 unfortunately the PR to fix this bug has already been merged: #1147

    I will close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions