Skip to content

PLR1708 false positives on nested functions #21162

@dscorbett

Description

@dscorbett

Summary

stop-iteration-return (PLR1708) reports false positives when a non-generator function raises StopIteration and contains a nested generator function, or a generator function contains a nested non-generator function that raises StopIteration. Example:

$ cat >plr1708.py <<'# EOF'
def f():
    def g():
        yield 1
    raise StopIteration

def g():
    def f():
        raise StopIteration
    yield 1
# EOF

$ ruff --isolated check plr1708.py --select PLR1708 --preview --output-format concise -q
plr1708.py:4:5: PLR1708 Explicit `raise StopIteration` in generator
plr1708.py:8:9: PLR1708 Explicit `raise StopIteration` in generator

Version

ruff 0.14.3 (8737a2d 2025-10-30)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpreviewRelated to preview mode featuresruleImplementing 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