FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

DocumentArray is not Generic for TypeVar · Issue #1146 · docarray/docarray · GitHub

DocumentArray is not Generic for TypeVar #1146

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL