-
-
Notifications
You must be signed in to change notification settings - Fork 458
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
Update django.db.models.functions
: allow Combinable
as parameter, add Round
function
#2195
Conversation
Per stubtest output, please also remove these entries from allowlist:
|
django.db.models.functions
: allow Combinable
parameters, add Round
function
django.db.models.functions
: allow Combinable
parameters, add Round
functiondjango.db.models.functions
: allow Combinable
as parameter, add Round
function
Done |
@@ -41,14 +41,14 @@ class TruncBase(TimezoneMixin, Transform): | |||
tzinfo: Any | |||
|
|||
def __init__( | |||
self, expression: Expression, output_field: Field | None = ..., tzinfo: tzinfo | None = ..., **extra: Any | |||
self, expression: Combinable | str, output_field: Field | None = ..., tzinfo: tzinfo | None = ..., **extra: Any |
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.
I'm not very familiar QuerySet operators/functions.
Most Combinable
s seem to inherit from Expression
. Can you give an example of something that is Combinable
but not Expression
?
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.
Also some PostgreSQL functions are typehinted as BaseExpression | Combinable | str
. I wonder if there's a reason for that, or in practice all useful expressions already inherit from Combinable
.
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.
Sry, you already answered the first question in PR description. F()
objects inherit from Combinable
but not Expression
.
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.
I wonder if there's a reason for that, or in practice all useful expressions already inherit from
Combinable
.
But unless someone can think of a use case for BaseExpression
, I'm inclined to go with Combinable | str
. Let's not complicate things unless we know it's necessary.
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.
Thanks, looks good to me.
Leaving open for a bit, in case someone has thoughts on BaseExpression
: #2195 (comment)
Co-authored-by: Noam Kushinsky <[email protected]>
Looks good to me, I checked, all possible |
Thanks for confirming the class hierarchy wrt I'm not against adding simple tests, but our usual policy is to not require tests for simple stubs, I'd just merge this as is. Once these hints are fixed, it's very unlikely they will regress again. (The bigger challenge is remembering to use the correct types when new classes are added, but that can't really be covered with current test infra) |
I have made things!
This fixes the annotation for database functions which can take
F
objects and field names, not just anExpression
. Also added annotation for the specializedRound
constructor.