Skip to content

[F821] Improve error message for anext/aiter #13287

@JP-Ellis

Description

@JP-Ellis

Summary

The lint F821 has a false positive with anext.

As pointed out by @MichaReiser, this ultimately is due to having either project.requires-python or tools.ruff.target-version set to a too lower version.

In this instances, it was discovered that Ruff was targeting Python 3.8 (from an erroneous config).

Example

async def foo(iter: AsyncGenerator[str, None]):
    assert await anext(iter)

Desired Behaviour

Where a symbol is introduced in a more recent version of Python, Ruff should:

  1. Still raise F821 as it is strictly correct; but also,
  2. Inform the use Ruff is assuming Python 3.x, and the symbol in question was only introduced in Python 3.y, and nudge the user to set reures-python or target-version.

Environment

ruff --version
ruff 0.6.4python --version
Python 3.12.5

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions