Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C417 false positive when not exactly 1 lambda parameter #15796

Closed
dscorbett opened this issue Jan 28, 2025 · 0 comments · Fixed by #15802
Closed

C417 false positive when not exactly 1 lambda parameter #15796

dscorbett opened this issue Jan 28, 2025 · 0 comments · Fixed by #15802

Comments

@dscorbett
Copy link

Description

unnecessary-map (C417) has a false positive in Ruff 0.9.3 when there is not exactly one lambda parameter. If the fix is enabled, it changes the program’s behavior by suppressing or changing the raised error.

$ cat >c417.py <<'# EOF'
try:
    print(list(map(lambda: 1, "xyz")))
except Exception as e:
    print(repr(e))
try:
    print(list(map(lambda x, y: x, [(1, 2), (3, 4)])))
except Exception as e:
    print(repr(e))
try:
    print(list(map(lambda x, y: x, "xyz")))
except Exception as e:
    print(repr(e))
# EOF

$ python c417.py
TypeError('<lambda>() takes 0 positional arguments but 1 was given')
TypeError("<lambda>() missing 1 required positional argument: 'y'")
TypeError("<lambda>() missing 1 required positional argument: 'y'")

$ ruff --isolated check  --select C417 c417.py --unsafe-fixes --fix
Found 3 errors (3 fixed, 0 remaining).

$ cat c417.py
try:
    print([1 for _ in "xyz"])
except Exception as e:
    print(repr(e))
try:
    print([x for x, y in [(1, 2), (3, 4)]])
except Exception as e:
    print(repr(e))
try:
    print([x for x, y in "xyz"])
except Exception as e:
    print(repr(e))

$ python c417.py
[1, 1, 1]
[1, 3]
ValueError('not enough values to unpack (expected 2, got 1)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant