Skip to content

Files

Latest commit

 

History

History
26 lines (17 loc) · 481 Bytes

contextmanager-generator-missing-cleanup.md

File metadata and controls

26 lines (17 loc) · 481 Bytes

Pattern: Context used in function will not be exited

Issue: -

Description

Used when a contextmanager is used inside a generator function and the cleanup is not handled.

Examples:

import contextlib


@contextlib.contextmanager
def cm():
    contextvar = "acquired context"
    print("cm enter")
    yield contextvar
    print("cm exit")


def genfunc_with_cm():
    with cm() as context:  # [contextmanager-generator-missing-cleanup]
        yield context * 2