@contextlib.contextmanager
def _refcounting(type_):
 gc.collect()
 refcount = len(objgraph.by_type(type_))
 (yield refcount)
 gc.collect()
 assert (len(objgraph.by_type(type_)) <= refcount), 'More {0!r} objects still in memory than before.'

@ contextlib . contextmanager def _refcounting ( type_ ) : gc . collect ( ) refcount = len ( objgraph . by_type ( type_ ) ) ( yield refcount ) gc . collect ( ) assert ( len ( objgraph . by_type ( type_ ) ) <= refcount ) , 'More {0!r} objects still in memory than before.'
perform the body of a with statement with reference counting for the given type --raises an assertion error if there are more unfreed objects of the given type than when we entered the with statement .