• Martin Teichmann's avatar
    bpo-30306: release arguments of contextmanager (GH-1500) · dd0e087e
    Martin Teichmann yazdı
    The arguments to a generator function which is declared as a
    contextmanager are stored inside the context manager, and
    thus are kept alive, even when it is used as a regular context
    manager, and not as a function decorator (where it needs
    the original arguments to recreate the generator on each
    call).
    
    This is a possible unnecessary memory leak, so this changes
    contextmanager.__enter__ to release the saved arguments,
    as that method being called means that particular CM instance
    isn't going to need to recreate the underlying generator.
    
    Patch by Martin Teichmann.
    dd0e087e
test_contextlib.py 32.1 KB