Skip to content

W0631:undefined-loop-variable false positive when for loop has function call that returns NoReturn #7311

Closed
@DetachHead

Description

@DetachHead

Bug description

from typing import NoReturn


def fail() -> NoReturn:
    ...

def foo(l):
    while True:
        for i in l:
            break
        else:
            continue
            # or break
            # or fail()
        print(i)

this is the same issue as #5971, though it seems to have only been fixed for return statements but not break, continue statements or function calls that return NoReturn or Never

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:8:14: W0631: Using possibly undefined loop variable 'i' (undefined-loop-variable)

Expected behavior

no error

Pylint version

pylint 2.14.5
astroid 2.11.7
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: undefined-variableIssues related to 'undefined-variable' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions