Ronald Oussoren <[email protected]> added the comment:
I'm not convinced that any change is needed, this is completely expected
behaviour (and not special to modules).
The following code also raises RecursionError:
class VerboseObject:
def __setattr__(self, nm, value):
print(f"Setting {nm} to {value}")
setattr(self, nm, value)
o = VerboseObject()
o.a = 42
This is because setattr() calls the __setattr__ method, which calls setattr()
again, ... .
The fix is to call super().__setattr__ instead:
class VerboseObject:
def __setattr__(self, nm, value):
print(f"Setting {nm} to {value}")
super().__setattr__(nm, value)
o = VerboseObject()
o.a = 42
----------
nosy: +ronaldoussoren
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com