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

fix: better generic support in document array stack by samsja · Pull Request #1147 · docarray/docarray · GitHub

fix: better generic support in document array stack - #1147

Merged
samsja merged 12 commits into
feat-rewrite-v2from
fix-generic
Feb 20, 2023
Merged

fix: better generic support in document array stack#1147
samsja merged 12 commits into
feat-rewrite-v2from
fix-generic

Conversation

samsja commented Feb 17, 2023
edited
Loading

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown

📝 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

How did you know this is what is required?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

is this even doing anything?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 changed the title Fix generic fix: better generic support in document array stack Feb 20, 2023

Jackmin801 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 mentioned this pull request Dec 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL