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

Raising len-as-conditions when using len on function returning generators or list comprehensions #4002

Open
Pierre-Sassoulas opened this issue Dec 31, 2020 · 0 comments
Labels
Astroid Related to astroid False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Dec 31, 2020

Describe the solution you'd like

The following code should be de-commented in len_checks.py and properly raise a len-as-condition:

    def function_returning_generator(r):
        for i in [r, 1, 2, 3]:
            yield i

    def function_returning_comprehension(r):
        return [x+1 for x in [r, 1, 2, 3]]

    def function_returning_function(r):
        return function_returning_generator(r)
      

    assert len(function_returning_generator(z))   # [len-as-condition]
    assert len(function_returning_comprehension(z))   # [len-as-condition]
    assert len(function_returning_function(z))   # [len-as-condition]

Additional context

But this require an evolution in astroid first. See #3821 (comment)

@Pierre-Sassoulas Pierre-Sassoulas added the Astroid Related to astroid label Dec 31, 2020
@Pierre-Sassoulas Pierre-Sassoulas added the False Negative 🦋 No message is emitted but something is wrong with the code label Dec 31, 2020
@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid False Negative 🦋 No message is emitted but something 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

1 participant