From fc48b56086becaf038b64009493d4c05ab40c32f Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Fri, 22 Dec 2023 08:12:48 +0100 Subject: [PATCH] Fix: false negative in FURB111 (#313) * fix false negative in FURB111 * Fix linter error, update test data file --------- Co-authored-by: dosisod <39638017+dosisod@users.noreply.github.com> --- refurb/checks/readability/use_func_name.py | 5 ++++- test/data/err_111.py | 4 ++++ test/data/err_111.txt | 13 +++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/refurb/checks/readability/use_func_name.py b/refurb/checks/readability/use_func_name.py index 362ebdd..b40ba03 100644 --- a/refurb/checks/readability/use_func_name.py +++ b/refurb/checks/readability/use_func_name.py @@ -10,10 +10,12 @@ LambdaExpr, ListExpr, NameExpr, + RefExpr, ReturnStmt, TupleExpr, ) +from refurb.checks.common import stringify from refurb.error import Error @@ -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 "" diff --git a/test/data/err_111.py b/test/data/err_111.py index d926415..b5f239d 100644 --- a/test/data/err_111.py +++ b/test/data/err_111.py @@ -3,6 +3,8 @@ def f(x, y): pass +mod = object + lambda: print() lambda x: bool(x) @@ -12,6 +14,8 @@ def f(x, y): lambda: {} lambda: () +lambda x: mod.cast(x) + # these will not diff --git a/test/data/err_111.txt b/test/data/err_111.txt index 93b53f9..393efa4 100644 --- a/test/data/err_111.txt +++ b/test/data/err_111.txt @@ -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`