-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
my approach to ColumnElement[TypeEngine] was wrong, is still wrong, sqlalchemy-stubs had it right, and we have to change it #7519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've posted python/typing#999 just so i can get the most complete understanding of this possible. |
and they replied with where the feature is being discussed at python/typing#548 |
Type operations seem to be really limited in python at the moment, so even using a Protocol I don't see a way of doing what we seek. |
the linked discussions make it very clear that what I thought we could do is not supported at all right now, that a lot of people are looking for it, and maybe we'll get it "someday". So our direction now as far as that is clear. for pep-646 I'm still stumped, just posted python/typing#1001 . |
well while I wait for an answer to my pep 646 question, in the meantime, if we can't do pep646 and get a Row from a Select that's typed, this whole issue doesn't matter. re: the whole issue of declarative mapping like i proposed in https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3430, I'm thinking of just adding a new callable to ORM called mapped_column(). mapped_column(), column_property(), relationship() and all of those, return MapperProperty like they always do, and we get MapperProperty to act like Mapped[], and basically we're done. it doesn't actually matter how Column etc. are typed, either |
that's probably the best solution. |
Mike Bayer has proposed a fix for this issue in the main branch: initial reorganize for static typing https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3447 |
working with the pep-646 stuff I can now see the whole way I had us do sqlalchemy2-stubs, while it still looks more correct to me, is not workable, even in non-pep-646 cases.
The issue is this. If we have
ColumnElement[TypeEngine[_T]]
like we do now, there is no way in pep-484 to get that to resolve into "_T", which is what we need when we execute SQL statements. A hypothetical methoddef scalar(self, scalar_select_statement)
as illustrated in the program below would need to be typed as:which is not supported: "TypeVar "Type[_TE@scalar]" is not subscriptable"
first program ilustrates the typing approach we have now, which ends down at the non-possible scalar method below:
second program illustrates how sqlalchemy-stubs did it, which while it still makes me wince to see
Column[int]
, is the only way we can get Python types back at the end, and this also will work in the pep-646 case. It's also how we didMapping[int]
in any case. So I was wrong.just as a note it's also not possible to have both types in the generic either, no way to extract "_T":
this significantly impacts the mypy plugin where the type indirection logic I have there would need to be removed. column expressions would just be typed to Python types directly and anything special about the specific TypeEngine in use has to be lost.
The text was updated successfully, but these errors were encountered: