Skip to content

PLE1142 false & missed alarms #14167

@jakkdl

Description

@jakkdl
def foo():
    ...

def should_not_give_PLE1142():
    (await x for x in foo())

def should_give_PLE1142():
    # note the list comprehension
    [x async for x in foo()]

# these latter two are correctly handled
def correctly_gives_PLE1142():
    (x for x in await foo())

def correctly_does_not_give_PLE1142():
    (x async for x in foo())

output:

$ ruff check --select=PLE1142 --isolated ruff_bug.py 
ruff_bug.py:5:6: PLE1142 `await` should be used within an async function
ruff_bug.py:12:17: PLE1142 `await` should be used within an async function
ruff_bug.py:13:6: PLE1142 `await` should be used within an async function
$ ruff --version
ruff 0.3.7

it should error on 9, 12 and 13.

Generator expressions only immediately evaluate the target, so the other fields do not need to be validated. And you appear to have missed async for completely for this check, but make sure to not enable that for generator expressions.
If you don't want to take my word for it or go dig through PEPs you can verify this by simply trying to let python parse the file, it will give a SyntaxError for 9/12/13 (though it abandons parsing the file on first error so you'll need to progressively comment out stuff to check)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions