Skip to content

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

@AnneYang720 AnneYang720 commented Feb 27, 2023

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
JoanFM previously requested changes Feb 27, 2023
Comment thread tests/integrations/document/test_document.py Outdated

@JohannesMessner 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.

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

@samsja 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.

good job ! I added a small requests

@JohannesMessner 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.

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

Copy link
Copy Markdown

📝 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