Conversation
typemap/type_eval/_apply_generic.py
Outdated
| if isinstance(ty, dict): | ||
| return ty |
There was a problem hiding this comment.
I changed Table to just take a string literal instead of a typed dict.
It turns out that's ends up being really weird to support.
tests/test_qblike_3.py
Outdated
|
|
||
|
|
||
| type ReplaceNever[T, D] = T if not Sub[T, Never] else D | ||
| type GetFieldItem[T: InitField, K, Default] = ReplaceNever[ |
There was a problem hiding this comment.
Nice thought with the Default
msullivan
left a comment
There was a problem hiding this comment.
This is an impressive scaling up of the fastapilike approach (good to see it works!), but not quite what I was looking for.
The thing I was interested in seeing modeled better was some of the query builder functions, like https://docs.sqlalchemy.org/en/20/orm/queryguide/select.html#selecting-multiple-orm-entities-simultaneously and https://docs.sqlalchemy.org/en/20/orm/queryguide/select.html#selecting-individual-attributes
1221bd6 to
8dc8e62
Compare
|
Possible syntax for fields Option 1 - Put more parameters in the type annotation class FieldAttrArgs(TypedDict, total=False):
db_type: ReadOnly[DbType]
class Field[Args: FieldAttrArgs](InitField[Args]):
pass
class FieldInitArgs(TypedDict, total=False):
nullable: ReadOnly[bool]
class field[Args: FieldInitArgs](InitField[Args]):
pass
class User:
# either a:
name: Field(db_type=String(50)) = field(nullable=False)
# or b:
name: Field[FieldAttrArgs(db_type=String(50))] = field(nullable=False)1a doesn't play nice with type checker. Option 2 - function which takes InitiField as param class Field[T]:
pass
class FieldArgs(TypedDict, total=False):
db_type: ReadOnly[DbType]
nullable: ReadOnly[bool]
def field[Args: FieldArgs](**kwargs: InitField[Args]) -> Field[GetAttr[Args, Literal["db_type"]]]:
...
class User:
name = field(db_type=String(50))we currently skip any unannotated fields? |
|
@dnwpark must be a member of the Vercel Labs team on Vercel to deploy. Learn more about collaboration on Vercel and other options here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Yeah, we'll probably want that. Another option would be to have (probably in addition) a
If we want to keep that, we'll probably need to add it as a built-in. We can't access If we didn't need to support runtime evaluation, and thus weren't restricting
We could probably add this?
Another option for implementing this, instead of using I think something like (Or maybe even just
If we do include The big thing here is that I want "type bools" to all be valid types also, and so I want all of the boolean type operators to return We can make this work with
The PEP calls for Another approach could be to try to represent things with a union instead of a tuple? |
| *( # Add entries if not present | ||
| [] | ||
| if IsSub[Literal[True], EntriesHasTable[Entries, New]] | ||
| else [MakeQueryEntryAllFields[New]] | ||
| ), |
There was a problem hiding this comment.
This syntax won't be supported in the type language.
It should be possible to make this work with an starred comprehension instead.
(Or also possibly with * and then a tuple type, but I don't think we have that implemented yet)
Add example that demonstrates the typing of a SQL-alchemy like query builder, allowing selects on tables and fields.
Single table queries such as
session.execute(select(User))will return a list ofMulti table queries such as
session.execute(select(User.name, Post.content))will return a list ofwhere
Things to think about:
Fieldcurrently needs both the table name and the attr name. This could be improved via some sort ofUpdateClass?GetAttr[Lhs, Prop]just gets the type of a member, not the fullMember. This is annoying if what I want is the init or quals.Split[T]orLeft/RightModelling an SQLite database like:
as: