-
-
Save jaraco/8fa0db176af7db2dd35ab6244c3f62b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import random | |
import functools | |
import contextlib | |
@functools.singledispatch | |
@contextlib.contextmanager | |
def make_context(obj): | |
yield random.randint(1, 100) | |
def test_referrers(): | |
obj = object() | |
assert len(gc.get_referrers(obj)) == 0 | |
with make_context(obj) as val: | |
assert len(gc.get_referrers(obj)) == 0 | |
del obj | |
assert isinstance(val, int) | |
__name__ == '__main__' and test_referrers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment