Skip to content

Conversation

@samsja
Copy link
Member

@samsja samsja commented Feb 17, 2023

Context

Make AbstractArray a generic compatbile with type var and string

fix this : #1146

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

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


def f(a: DocumentArray[T]) -> DocumentArray[T]:
    return a


def g(a: DocumentArray['BaseDocument']) -> DocumentArray['BaseDocument']:
    return a

this work now

@github-actions
Copy link

📝 Docs are deployed on https://ft-fix-generic--jina-docs.netlify.app 🎉

def __class_getitem__(cls, item: Type[BaseDocument]):
def __class_getitem__(cls, item: Union[Type[BaseDocument], TypeVar, str]):
if not isinstance(item, type):
return Generic.__class_getitem__.__func__(cls, item) # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you know this is what is required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this even doing anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this even doing anything?

this is not doing anything else than checking the the item is valid Generic. I think it does not harm to keep it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this even doing anything?

this is not doing anything else than checking the the item is valid Generic. I think it does not harm to keep it

Crashed in Python 3.12.0

    return Generic.__class_getitem__.__func__(cls, item)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'builtin_function_or_method' object has no attribute '__func__'. Did you mean: '__doc__'?

@samsja samsja changed the title Fix generic fix: better generic support in document array stack Feb 20, 2023
Copy link
Contributor

@Jackmin801 Jackmin801 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried with pydantic generic model. Seems to work

954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
Signed-off-by: 954 <[email protected]>

fix: judge based on Python version

Signed-off-by: 954 <[email protected]>

fix: format for black

Signed-off-by: 954 <[email protected]>
954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
JoanFM pushed a commit that referenced this pull request Dec 22, 2023
@JoanFM JoanFM mentioned this pull request Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants