Skip to content

all(...) rewrite produces incorrect results #5372

@asottile

Description

@asottile

this is boiled down from a more complicated case

def test():
    y = range(5)
    assert not all(x for x in y)
$ pytest t.py
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-4.6.1, py-1.8.0, pluggy-0.12.0
rootdir: /tmp
collected 1 item                                                               

t.py F                                                                   [100%]

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

    def test():
        y = range(5)
>       assert not all(x for x in y)
E       assert 0

t.py:3: AssertionError
=========================== 1 failed in 0.04 seconds ===========================
$ pytest t.py --assert=plain
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-4.6.1, py-1.8.0, pluggy-0.12.0
rootdir: /tmp
collected 1 item                                                               

t.py .                                                                   [100%]

=========================== 1 passed in 0.01 seconds ===========================```

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions