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 has multiple problems #15809

Open
InSyncWithFoo opened this issue Jan 29, 2025 · 0 comments
Open

C417 has multiple problems #15809

InSyncWithFoo opened this issue Jan 29, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@InSyncWithFoo
Copy link
Contributor

InSyncWithFoo commented Jan 29, 2025

While working on #15802, I noticed a few problems with C417 (playground).

When list/set/dict from the outer call is an overshadowed binding, the inner map() call is not reported at all:

	map(lambda x: x, [])
#   ^^^^^^^^^^^^^^^^^^^^ Reported

	list(map(lambda x: x, []))
#   ^^^^^^^^^^^^^^^^^^^^^^^^^^ Outer `list()` call reported, nested `map()` call not reported

	def _():
		list = ...  # Overshadowed

		map(lambda x: x, [])
#       ^^^^^^^^^^^^^^^^^^^^ Reported

		list(map(lambda x: x, []))  # Currently no error
#            ^^^^^^^^^^^^^^^^^^^^ This should be reported on its own merit

If the iterable is a starred expression, the fix outputs a comprehension with different semantics:

a = [(1, 2), (3, 4)]

# Before
map(lambda x: [*x, 10], *a)  # TypeError: <lambda>() takes 1 positional argument but 2 were given

# After
([*x, 10] for x in a)        # [1, 2, 10], [3, 4, 10]

The rule currently also doesn't report when there are multiple iterables:

map(lambda x, y: x + y, a, b)  # Currently no error

# Can be simplified to:
(x + y for x, y in zip(a, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants