This repository was archived by the owner on Dec 8, 2023. It is now read-only.
Add pattern to replace if-else block with dict.get() when possible#21
Merged
morgante merged 2 commits intogetgrit:mainfrom Sep 19, 2023
vlopezferrando:dict-get
Merged
Add pattern to replace if-else block with dict.get() when possible#21morgante merged 2 commits intogetgrit:mainfrom vlopezferrando:dict-get
morgante merged 2 commits intogetgrit:mainfrom
vlopezferrando:dict-get
Conversation
morgante
suggested changes
Sep 18, 2023
| engine marzano(0.1) | ||
| language python | ||
|
|
||
| // NOTE: if $key or $default call functions with side effects, this transform is not safe |
Contributor
There was a problem hiding this comment.
Let's handle that in the code. You can use a where clause.
Contributor
Author
There was a problem hiding this comment.
Done, I have added:
where {
!$key <: contains call(),
!$default <: contains call(),
}
Of course, in Python it is tricky to 100% enforce this, as an operator could be overloaded with anything.
morgante
approved these changes
Sep 19, 2023
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Join multiple with statements into a single one. Rule SIM401 from flake8-simplify.
Caveat: if either the key or the default value are functions, they will be called a different
number of times in the generated code. We may need to enforce that
$keyand$defaultdon'tcall any function.