Skip to content

implicit casting for predefined type #1056

@samsja

Description

@samsja

Context

Instantiating a predefined document is quite verbose atm

from docarray import BaseDocument
from docarray.documents import Text, Image

class MyDoc(BaseDocument):
    text: Text
    image: Image

my_doc = MyDoc(text=Text(text='hello'), image=Image(url='http://fjdjnsfsger.jpg')))

We want to make it less verbose

proposition

cast

we could allow doing the following

my_doc = MyDoc(text='hello', image='http://fdsgd.jpg')

and automatically "cast" or validate

This has been merged in #1058

Init less verbose (#1067)

txt = Text(text='hello')

is too verbose, we should allow doing

txt = Text('hello')

We should rely on the same mechanism as for the validation of this pr #1058

Metadata

Metadata

Assignees

Labels

DocArray v2This issue is part of the rewrite; not to be merged into main

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions