[ ] Have you checked to see if your issue still exists on the master branch? See the docs for instructions on how to setup a local build of Refurb.
[X] Have you looked at the open/closed issues to see if anyone has already reported your issue?
[X] If reporting a false positive/incorrect suggestion, have you double checked that the suggested fix changes the code semantics?
The Bug
The following code:
def expensive_func_or_complex_expression(a):
# <snip logic...>
return a
def foo(bar):
match expensive_func_or_complex_expression(bar):
case "a":
return 123
case result:
return result
Emits the following error:
$ refurb testcase.py
testcase.py:11:13 [FURB126]: Replace `case _: return x` with `return x`
Run `refurb --explain ERR` to further explain an error. Use `--quiet` to silence this message
But it should not be emitting an error instance because the match is on an expression that I don't want to repeat.
The most straightforward interpretation of the suggested fix would be doing:
def foo(bar):
match expensive_func_or_complex_expression(bar):
case "a":
return 123
return expensive_func_or_complex_expression(bar)
but that's bad.
Doing
def foo(bar):
result = expensive_func_or_complex_expression(bar)
match result:
case "a":
return 123
return result
is not too bad but I prefer the original form. This also isn't a super obvious change to make based on the error suggestion as it mentions case _ but I'm not using the underscore pattern.
Has your issue already been fixed?
master
branch? See the docs for instructions on how to setup a local build of Refurb.The Bug
The following code:
Emits the following error:
But it should not be emitting an error instance because the match is on an expression that I don't want to repeat.
The most straightforward interpretation of the suggested fix would be doing:
but that's bad.
Doing
is not too bad but I prefer the original form. This also isn't a super obvious change to make based on the error suggestion as it mentions
case _
but I'm not using the underscore pattern.Version Info
Python Version
Python 3.10.12
Config File
Extra Info
None