<s> """<STR_LIT>""" <EOL> import weakref <EOL> import gc <EOL> from contextlib import contextmanager <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class ReferenceError ( AssertionError ) : <EOL> pass <EOL> def set_gc_state ( state ) : <EOL> """<STR_LIT>""" <EOL> if gc . isenabled ( ) == state : <EOL> return <EOL> if state : <EOL> gc . enable ( ) <EOL> else : <EOL> gc . disable ( ) <EOL> @ contextmanager <EOL> def gc_state ( state ) : <EOL> """<STR_LIT>""" <EOL> orig_state = gc . isenabled ( ) <EOL> set_gc_state ( state ) <EOL> yield <EOL> set_gc_state ( orig_state ) <EOL> @ contextmanager <EOL> def assert_deallocated ( func , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> with gc_state ( False ) : <EOL> obj = func ( * args , ** kwargs ) <EOL> ref = weakref . ref ( obj ) <EOL> yield obj <EOL> del obj <EOL> if ref ( ) is not None : <EOL> raise ReferenceError ( "<STR_LIT>" ) </s>
