New submission from Zorceta:

Code and result:

```
>>> class A:
        def __init__(self):
                self.data = {'a': 1, 'b': 2, 'c': 3}
        def __getattr__(self, name):
                print('in __getattr__, getting %s' % name)
                if name in self.data:
                        return self.data[name]
                else:
                        raise AttributeError
        def __setattr__(self, name, value):
                print('in __setattr__, setting %s to %s' % (name, value))
                if name in self.data:
                        self.data[name] = value
                else:
                        self.__class__.__setattr__(self, name, value)

                        
>>> a = A()
in __setattr__, setting data to {'a': 1, 'b': 2, 'c': 3}
in __getattr__, getting data
in __getattr__, getting data
in __getattr__, getting data
......
```

>From above you can see it stuck on

>>> if name in self.data:

in `__setattr__`.

But, the result indicates that `__setattr__` uses `__getattr__` to read the 
`data` attribute, which is against docs:

"Note that if the attribute is found through the normal mechanism, 
__getattr__() is not called."

If it acts as described, `data` should be read "through the normal mechanism", 
not through `__getattr__`.

----------
messages: 246453
nosy: zorceta
priority: normal
severity: normal
status: open
title: Customized attribute access causes infinite loop
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24590>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to