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

cell-var-from-loop (W0640): why #5263

Open
bersbersbers opened this issue Nov 5, 2021 · 4 comments
Open

cell-var-from-loop (W0640): why #5263

bersbersbers opened this issue Nov 5, 2021 · 4 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@bersbersbers
Copy link

Bug description

I don't see why the code in this example file

https://github.com/PyCQA/pylint/blob/96e84595194073ea54a8c7730b86125049c0f4f9/tests/functional/n/nested_func_defined_in_loop.py#L1-L10

is problematic. When called using example(range(4)), it outputs

0
1
2
3
0
1
2
3

which looks correct to me. See also sprytnyk/pylint-errors#7

Configuration

No response

Command used

wget https://raw.githubusercontent.com/PyCQA/pylint/main/tests/functional/n/nested_func_defined_in_loop.py
pylint nested_func_defined_in_loop.py

Pylint output

************* Module nested_func_defined_in_loop
nested_func_defined_in_loop.py:7:18: W0640: Cell variable i defined in loop (cell-var-from-loop)

-----------------------------------
Your code has been rated at 8.57/10

Expected behavior

No error

Pylint version

pylint 2.11.1
astroid 2.8.4
Python 3.9.6 (default, Jan  1 1970, 00:00:00) 
[GCC 7.5.0]

OS / Environment

OpenSUSE Leap 15.2

Additional dependencies

No response

@bersbersbers bersbersbers added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 5, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Discussion 🤔 Question and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 5, 2021
@DanielNoord
Copy link
Collaborator

@Pierre-Sassoulas This actually seems to be a false positive.

We have:
https://github.com/PyCQA/pylint/blob/8e15c1dd9d0dc07cb9794353a32cd37d57f2d569/tests/functional/c/cellvar_escaping_loop.py#L134-L142

But this is different because nested isn't called which makes the loop variable escape. That doesn't happen in the example provided here.

Looking at some of the good_case's in those tests I don't see something that resembles this example. Should we allow this pattern?

@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Question Discussion 🤔 labels Nov 13, 2021
@Pierre-Sassoulas
Copy link
Member

Thank you for taking the time to look into it, I agree with you, let's add a new "good" test case.

@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jul 4, 2022
@Pierre-Sassoulas
Copy link
Member

#7100 should probably be done at the same time.

@ericvergnaud
Copy link

Here is another example of a false positive:

def some_function(samples: list[dict], *names: str):
    for name in names:
        # pylint warning W0640 here is a pylint bug (verified manually)
        filtered_samples = [s["some_key"] for s in filter(lambda s: s["some_key"]["some_name"] == name, samples)]
    # do something with filtered_samples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

4 participants