Skip to content

Commit

Permalink
Fix: false negative in FURB111 (#313)
Browse files Browse the repository at this point in the history
* fix false negative in FURB111

* Fix linter error, update test data file

---------

Co-authored-by: dosisod <[email protected]>
  • Loading branch information
sbrugman and dosisod authored Dec 22, 2023
1 parent 39cafb0 commit fc48b56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion refurb/checks/readability/use_func_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
LambdaExpr,
ListExpr,
NameExpr,
RefExpr,
ReturnStmt,
TupleExpr,
)

from refurb.checks.common import stringify
from refurb.error import Error


Expand Down Expand Up @@ -59,13 +61,14 @@ def check(node: LambdaExpr, errors: list[Error]) -> None:
arguments=lambda_args,
body=Block(
body=[
ReturnStmt(expr=CallExpr(callee=NameExpr(name=func_name)) as func),
ReturnStmt(expr=CallExpr(callee=RefExpr() as ref) as func),
]
),
) if (
get_lambda_arg_names(lambda_args) == get_func_arg_names(func.args)
and all(kind == ArgKind.ARG_POS for kind in func.arg_kinds)
):
func_name = stringify(ref)
arg_names = get_lambda_arg_names(lambda_args)
arg_names = ", ".join(arg_names) if arg_names else ""

Expand Down
4 changes: 4 additions & 0 deletions test/data/err_111.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
def f(x, y):
pass

mod = object


lambda: print()
lambda x: bool(x)
Expand All @@ -12,6 +14,8 @@ def f(x, y):
lambda: {}
lambda: ()

lambda x: mod.cast(x)


# these will not

Expand Down
13 changes: 7 additions & 6 deletions test/data/err_111.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
test/data/err_111.py:7:1 [FURB111]: Replace `lambda: print()` with `print`
test/data/err_111.py:8:1 [FURB111]: Replace `lambda x: bool(x)` with `bool`
test/data/err_111.py:9:1 [FURB111]: Replace `lambda x, y: f(x, y)` with `f`
test/data/err_111.py:11:1 [FURB111]: Replace `lambda: []` with `list`
test/data/err_111.py:12:1 [FURB111]: Replace `lambda: {}` with `dict`
test/data/err_111.py:13:1 [FURB111]: Replace `lambda: ()` with `tuple`
test/data/err_111.py:9:1 [FURB111]: Replace `lambda: print()` with `print`
test/data/err_111.py:10:1 [FURB111]: Replace `lambda x: bool(x)` with `bool`
test/data/err_111.py:11:1 [FURB111]: Replace `lambda x, y: f(x, y)` with `f`
test/data/err_111.py:13:1 [FURB111]: Replace `lambda: []` with `list`
test/data/err_111.py:14:1 [FURB111]: Replace `lambda: {}` with `dict`
test/data/err_111.py:15:1 [FURB111]: Replace `lambda: ()` with `tuple`
test/data/err_111.py:17:1 [FURB111]: Replace `lambda x: mod.cast(x)` with `mod.cast`

0 comments on commit fc48b56

Please sign in to comment.