8000 feat: dynamic class creation by AnneYang720 · Pull Request #1179 · docarray/docarray · GitHub
[go: up one dir, main page]

Skip to content

feat: dynamic class creation#1179

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

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

Conversation

@AnneYang720
Copy link
Contributor
@AnneYang720 AnneYang720 commented Feb 27, 2023

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
JoanFM previously requested changes Feb 27, 2023
Copy link
Member
@JohannesMessner JohannesMessner left a comment

Choose a reason for hiding this comment

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

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

Signed-off-by: AnneY <evangeline-lun@foxmail.com>
@github-actions github-actions bot added size/m and removed size/s labels Feb 27, 2023
Signed-off-by: AnneY <evangeline-lun@foxmail.com>
Copy link
Member
@samsja samsja left a comment

Choose a reason for hiding this comment

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

good job ! I added a small requests

Copy link
Member
@JohannesMessner JohannesMessner left a comment

Choose a reason for hiding this comment

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

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>
@github-actions
Copy link

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

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

0