zopefoundation / Acquisition

Acquisition is a mechanism that allows objects to obtain attributes from the containment hierarchy they're in.
Other
12 stars 12 forks source link

PURE_PYTHON: bad (maybe redundant) "special method"s implementation #51

Closed d-maurer closed 3 years ago

d-maurer commented 3 years ago

The pure Python version implements the _Wrapper special methods wrongly: consider the following case:

from Acquisition import Implicit
class I(Implicit):
  def add(self, id):
    o = I(); o.id = id
    setattr(self, id, o)
    return getattr(self, id)

top = I()
f = top.add("f")
f2 = f.f

Calling bool(f2) causes an infinite loop:

>>> bool(f2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dieter/tmp/ec/Acquisition/src/Acquisition/__init__.py", line 545, in __nonzero__
    return bool(nonzero(self))  # Py3 is strict about the return type
  File "/home/dieter/tmp/ec/Acquisition/src/Acquisition/__init__.py", line 545, in __nonzero__
    return bool(nonzero(self))  # Py3 is strict about the return type
  File "/home/dieter/tmp/ec/Acquisition/src/Acquisition/__init__.py", line 545, in __nonzero__
    return bool(nonzero(self))  # Py3 is strict about the return type
  [Previous line repeated 988 more times]
  File "/home/dieter/tmp/ec/Acquisition/src/Acquisition/__init__.py", line 535, in __nonzero__
    aq_self = self._obj
  File "/home/dieter/tmp/ec/Acquisition/src/Acquisition/__init__.py", line 412, in __getattribute__
    return _OGA(self, name)
RecursionError: maximum recursion depth exceeded while calling a Python object