-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Typing: fix type of func.coalesce when used with hybrid properties #12963
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
Conversation
| @overload | ||
| def coalesce( | ||
| self, | ||
| col: ColumnElement[_T], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: we cannot add Optional[_T] here, otherwise the inferred type of the result will always be coalese[Optional[_T]]. But without any change everything seems to be working as expected, and it’s covered by the typing tests.
sqla-tester
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 9102d5c of this pull request into gerrit so we can run tests and reviews and stuff
|
New Gerrit review created for change 9102d5c: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343 |
|
i have to fix pep484 github hook, because it uses py3.14 , let me see hwat i can do |
|
Thanks! In the meantime I’ve fixed the flake8 errors in my branch, but now I see that this code is actually generated. I’ll look into it. |
|
if you rebase on main, that pep484 should be working now |
Result: error: Expression is of type "coalesce[int | None]", not "coalesce[int]" [assert-type]
7005373 to
05d0d97
Compare
sqla-tester
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 05d0d97 of this pull request into gerrit so we can run tests and reviews and stuff
|
Patchset 05d0d97 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343 |
sqla-tester
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Federico Caselli (CaselIT) wrote:
code review left on gerrit
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343
| def coalesce( | ||
| self, | ||
| col: _ColumnExpressionArgument[_T], | ||
| col: _ColumnExpressionArgument[Optional[_T]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Federico Caselli (CaselIT) wrote:
not 100% correct but I guess it's fine in 99% of cases where coalesce is used
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Michael Bayer (zzzeek) wrote:
Done
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Federico Caselli (CaselIT) wrote:
Done
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343
sqla-tester
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Michael Bayer (zzzeek) wrote:
code review left on gerrit
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343
| builtins = set(dir(__builtins__)) | ||
| for key, fn_class in _fns_in_deterministic_order(): | ||
| is_reserved_word = key in builtins | ||
| is_first_arg_optional = fn_class.__name__ == "coalesce" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Michael Bayer (zzzeek) wrote:
oh, i dont like this part. hardcoding to a name like that. let me see what else can be done
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343
|
Federico Caselli (CaselIT) wrote: code review left on gerrit View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343 |
|
Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6343 has been merged. Congratulations! :) |
|
Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6426 has been merged. Congratulations! :) |
Fixed typing issue where :class:`.coalesce` would not return the correct return type when a nullable form of that argument were passed, even though this function is meant to select the non-null entry among possibly null arguments. Pull request courtesy Yannick PÉROUX. Closes: #12963 Pull-request: #12963 Pull-request-sha: 05d0d97 Change-Id: Ife83a384ea57faf446c1fdb542df14627348f40f (cherry picked from commit d160cb5)
Description
When
func.coalesceis used with a hybrid property, the return type inferred is wrong. This can lead to suprising mypy errors, such as this:Mypy output:
This PR aims to fix this issue.
Checklist
This pull request is:
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
Fixes: #<issue number>in the commit messageinclude a complete example of how the feature would look.
Fixes: #<issue number>in the commit messageHave a nice day!