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

feat: dynamic class creation by AnneYang720 · Pull Request #1179 · docarray/docarray · GitHub

feat: dynamic class creation - #1179

Merged
samsja merged 9 commits into
feat-rewrite-v2from
feat-dynamic-creation
Feb 28, 2023
Merged

feat: dynamic class creation#1179
samsja merged 9 commits into
feat-rewrite-v2from
feat-dynamic-creation

Conversation

AnneYang720 commented Feb 27, 2023
edited
Loading

Copy link
Copy Markdown
Contributor

Goals:

This PR is for issue #1152

In the issue, Pydantic's create_model was mentioned. In order for the function to return a subclass of BaseDocument, we need to pass the parameter __base__.

  • code
  • tests

Signed-off-by: AnneY <evangeline-lun@foxmail.com>
Signed-off-by: AnneY <evangeline-lun@foxmail.com>
JoanFM previously requested changes Feb 27, 2023

JohannesMessner left a comment

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

I think we should split this out into two functions:

  • one that mirrors create_model as closely as possible, has a similar name, takes all the same arguments, and just makes sure that the __base__ is set correctly. It should also take the fields in the same way pydantic does
  • another, slightly higher level one, that would be called creat_from_dict, and take the fields as a dictionary. This would also closely mirror functionality in pydantic: https://docs.pydantic.dev/usage/models/#model-creation-from-namedtuple-or-typeddict

Comment thread docarray/documents/helper.py Outdated
Comment thread docarray/documents/helper.py Outdated
Comment thread docarray/documents/helper.py Outdated
Signed-off-by: AnneY <evangeline-lun@foxmail.com>
github-actions Bot added size/m and removed size/s labels Feb 27, 2023
Signed-off-by: AnneY <evangeline-lun@foxmail.com>
Comment thread docarray/documents/helper.py Outdated
Comment thread docarray/documents/helper.py Outdated

samsja left a comment

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

good job ! I added a small requests

JohannesMessner left a comment

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

Nice! Should we also have something that creates from normal dict by looking at the data and "guessing" the type? This would be different from what pydantic can do, and could be a separate PR

Signed-off-by: AnneY <evangeline-lun@foxmail.com>
Comment thread docarray/documents/helper.py Outdated

Copy link
Copy Markdown

📝 Docs are deployed on https://ft-feat-dynamic-creation--jina-docs.netlify.app 🎉

samsja merged commit e851ce2 into feat-rewrite-v2 Feb 28, 2023
samsja deleted the feat-dynamic-creation branch February 28, 2023 13:02
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.

4 participants


Back | FazBrowse Home | New Git URL