[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.
_______________________________________________
python-committers mailing list -- python-committers@python.org
To unsubscribe send an email to python-committers-le...@python.org
https://mail.python.org/mailman3/lists/python-committers.python.org/
Message archived at 
https://mail.python.org/archives/list/python-committers@python.org/message/UZKFQAYF2X7MIQO7WLXPFTDHXGSJZ55K/
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to