Skip to content

[red-knot] false positive "possibly not defined" for symbol used in generator expression inside for loop #13879

@alex

Description

@alex

(I'm aware that red-knot is not yet stable).

This was tested with 7dbd8f0f8e725d05cc1d15e6ef1c6cc2ed2b2090 with no Ruff settings.

Code:

import datetime


def get_weeks() -> list[datetime.date]:
    raise NotImplementedError


def get_week_groups() -> list[list[datetime.date]]:
    pass


def main():
    weeks = get_weeks()
    all_week_groups = get_week_groups()
    for week in weeks:
        for group in all_week_groups:
            if any(d == week for d in group):
                print("Blah")

red-knot output:

/t/ruff ❯❯❯ ./target/release/red_knot --current-directory=z/
ERROR /private/tmp/ruff/z/t.py:17:25: Name `week` used when possibly not defined

But obviously week is always defined there.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtyMulti-file analysis & type inference

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions