[x] Typed link properties (except Python 3.7 which doesn't have typing.Literal)
[x] Different Python versions
[x] Add tests
~edgedb/edgedb#4325 is preferred to generate more friendly code.~
Prior 2.2 EdgeDB always return AT_MOST_ONE as result_cardinality for single results, so there will be a false typing.Optional even if the actual cardinality is ONE.
edgedb.Range is supported, but it doesn't support Pydantic/FastAPI out of the box.
Generated sample:
from __future__ import annotations
import dataclasses
import edgedb
import enum
import typing
import uuid
MyString = str
class NoPydanticValidation:
@classmethod
def __get_validators__(cls):
from pydantic.dataclasses import dataclass as pydantic_dataclass
pydantic_dataclass(cls)
cls.__pydantic_model__.__get_validators__ = lambda: []
return []
class Color(enum.Enum):
RED = "Red"
GREEN = "Green"
BLUE = "Blue"
@dataclasses.dataclass
class FullQueryResult(NoPydanticValidation):
id: uuid.UUID
mystr: MyString
literal: int
enumval: Color
userstr: str
user: list[FullQueryResultUserItem]
num: FullQueryResultNum | None
named: FullQueryResultNamed
arr: list[int]
tup: tuple[int, int, int]
intrange: edgedb.Range[int]
class FullQueryResultNamed(typing.NamedTuple):
a: int
b: float
@dataclasses.dataclass
class FullQueryResultNum(NoPydanticValidation):
id: uuid.UUID
n: int
@dataclasses.dataclass
class FullQueryResultUserItem(NoPydanticValidation):
id: uuid.UUID
mobile: str
role: FullQueryResultUserItemRole | None
@dataclasses.dataclass
class FullQueryResultUserItemRole(NoPydanticValidation):
id: uuid.UUID
name: str
async def full_query(
client: edgedb.AsyncIOClient,
arg0: str,
) -> FullQueryResult | None:
return await client.query_single(
"""\
select {
mystr := <MyString>'abc',
literal := 42,
enumval := <Color>'Red',
userstr := <str>$0,
user := (select User { mobile, role: { name } }),
num := (select {{n := 1},{},{}} limit 2),
named := (a := 1, b := 2.2),
arr := [1,2,3],
tup := (1,2,3),
intrange := range(9, 16),
}\
""",
arg0,
)
Please review individual commits.
array
,set
,namedtuple
andtuple
should support__deepcopy__()
so thatdataclass.asdict()
could properly handle theobject
with such fields.~describe_query()
APItyping.Literal
)~edgedb/edgedb#4325 is preferred to generate more friendly code.~
typing.Optional
even if the actual cardinality is ONE.edgedb.Range
is supported, but it doesn't support Pydantic/FastAPI out of the box.Generated sample: