This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve type annotations for execute_values
.
#12311
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
252a71e
Add note about how we could use ParamSpec in _do_execute
reivilibre 31b36c9
Add a narrower type annotation for execute_values's `args` parameter
reivilibre 0732a86
`values` is a better name than `args`
reivilibre e5785b1
Newsfile
reivilibre 470d309
Revert "Add note about how we could use ParamSpec in _do_execute"
reivilibre 8d58994
Don't thread args through _do_execute needlessly
reivilibre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve type annotations for `execute_values`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(This code was pre-existing, but...)
the_sql
doesn't change for each iterate, correct? So really no reason to pass it in for each one?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.
Sorry, what do you mean?
the_sql
is given by_do_execute
.the_values
are just a pass-through ofvalues
and could have been part of the lambda's closure, but in analogue toexecute_batch
(and indeed the way this code was written before), it's passed through. If we want to change this I suppose I have no objections, though I wonder if the idea was that_do_execute
could have transformed the args if 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.
(Maybe the confusion here is that there's no iteration here: it's a one-off callback)
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.
Errr, yes...that didn't make sense.
My confusion is -- why are we passing in
fetch
directly into the lambda, but we pass inthe_sql
andthe_values
as arguments to the lambda?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.
the_sql
is not something we know, since_do_execute
computes it.the_values
is something we indeed could pass straight in.I wonder if the reason is historical: perhaps
fetch = True
(a keyword argument) didn't come until later; perhaps the code used to look like:EDIT: this seems likely because:
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.
Maybe
_do_execute
should just allow kwargs instead? I think that would be cleaner?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.
Ah, nevermind.
execute_values
isn't a method, so it'd need a lambda to shuffle the parameters around anywayThere 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.
Ah, I did not realize that
_do_execute
modified the passed insql
!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've changed this around a bit, is that better to you?
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 do find that clearer, yes!