Skip to content

fallible-context-manager (RUF075) - false positive when yield is inside for loop with no cleanup afterwards #25378

@DetachHead

Description

@DetachHead

Summary

from contextlib import contextmanager

@contextmanager
def foo(items: list[int]):
    for value in items:
        yield # RUF075: Context manager does not catch exceptions
        break
[lint]
preview = true
select = [ "RUF075" ]

Playground

as discussed in #15629 (comment) we wanted to avoid false positives when yield is the last statement, but it would be nice if it was also able to detect if there's a break statement right after it when the surrounding for loop is the last statement

Version

0.15.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated to preview mode featuresruleImplementing or modifying a lint rule

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions