[Tim]
And if a type pointer is the only thing being visited, then there's no point unless the object can itself be reachable from the type object.
{Pablo]
But that could happen easily for heap types as they are mutable by default. For instance, you set the instance in a global:
type -> module -> globals -> instance -> type
Sorry, but this is apparently a rat's nest and that's too sketchy for me ;-)
Can you flesh this out for what stumbled into being my running example? That is, how could a regexp pattern object be part of a cycle?
import re p = re.compile("ab*c") type(p) <class 're.Pattern'> type(p).__module__ 're' type(type(p).__module__) <class 'str'>
That is, its __module__ attribute is a string, not a module object.
And, in general, I can't add attributes to p, or change their bindings:
p.flags 32 p.flags = re Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: readonly attribute p.newattr = re Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 're.Pattern' object has no attribute 'newattr'
I just don't see a way to trick it into being part of a cycle.
Not denying that safe is better than sorry, though.