Skip to content

fix: better generic support in document array stack #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 20, 2023
Merged

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

Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
Signed-off-by: samsja <sami.jaghouar@hotmail.fr>
@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
Signed-off-by: 954 <510485871@qq.com>
954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
Signed-off-by: 954 <510485871@qq.com>

fix: judge based on Python version

Signed-off-by: 954 <510485871@qq.com>

fix: format for black

Signed-off-by: 954 <510485871@qq.com>
954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
Signed-off-by: 954 <510485871@qq.com>
954-Ivory added a commit to 954-Ivory/docarray that referenced this pull request Dec 22, 2023
Signed-off-by: 954 <510485871@qq.com>
JoanFM pushed a commit that referenced this pull request Dec 22, 2023
Signed-off-by: 954 <510485871@qq.com>
@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.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy