feat: use walrus operator instead of match and if#22
feat: use walrus operator instead of match and if#22morgante merged 4 commits intogetgrit:mainfrom vlopezferrando:match-if-to-walrus
Conversation
.grit/patterns/re_match_walrus.md
Outdated
| ```python | ||
| # Convert this: | ||
| math = re.match(regex): | ||
| if match: | ||
| ... | ||
|
|
||
| # To this: | ||
| if math := re.match(regex): | ||
| ... | ||
| ``` |
There was a problem hiding this comment.
We should not have these sorts of snippets in descriptions. This is actually the exact point of the samples embedded in the markdown.
You can move this down below as the first sample for this pattern, and that will make it automatically tested.
.grit/patterns/re_match_walrus.md
Outdated
|
|
||
| ``` | ||
|
|
||
| ## Transforms a log statement |
There was a problem hiding this comment.
It's often easier to look at individual before/after pairs. I'd consider spitting this into multiple samples.
There was a problem hiding this comment.
Done, I've split all test cases.
.grit/patterns/re_match_walrus.md
Outdated
| }, | ||
| } | ||
|
|
||
| // TODO: we should also check if `re` is imported |
There was a problem hiding this comment.
Not sure I follow the difference here. Either way please resolve this todo and avoid commented out code.
There was a problem hiding this comment.
I've removed the comment. I was thinking of double-checking that re is an imported module and not something else, but I guess it's nitpicking.
Use the walrus operator for snippets with the pattern:
Limitations:
from re import match as m), it will not be transformed.re.matchis used, we do not check thatrecomes fromimport re.