fix(types): correct type hints for with_for_update to ForUpdateParameter #465
+40
−34
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.
Description
This change fixes the type hint for the
with_for_update
parameter in the repositories. Currently, the type hint isOptional[bool]
, but according to the method's docstring,with_for_update
is described as: "indicating FOR UPDATE should be used, or may be a dictionary containing flags to indicate a more specific set of FOR UPDATE flags for the SELECT". This implies that a dictionary may be passed, but the current type hint doesn’t reflect that.If we trace where
with_for_update
is passed, it ends up unchanged in session.refresh in SQLAlchemy, which has the type hintForUpdateParameter = Union["ForUpdateArg", None, bool, Dict[str, Any]]
, and that’s what I updated the type hints in our code to match.However, it’s possible that this isn’t what was originally intended, and I’m not sure if this is the correct fix. There are other ways to address the issue — which approach would be preferable?