Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardPythonrefcounting and cyclic GCSingle-choice MCQ

gc.get_referents(s) is called on an instance s of a class that uses __slots__ = ('p', 'q') and has no __dict__. The result includes the objects bound to s.p and s.q. Which interpreter mechanism makes the slot values visible to the collector?

import gc class S: __slots__ = ('p', 'q') s = S(); s.p = [1]; s.q = {'k': 2} print(s.p in gc.get_referents(s), s.q in gc.get_referents(s))