New submission from Denis Osipov <osipo...@list.ru>:
Customizing module attribute access example raises RecursionError: >>> import sys >>> from types import ModuleType >>> class VerboseModule(ModuleType): ... def __repr__(self): ... return f'Verbose {self.__name__}' ... def __setattr__(self, attr, value): ... print(f'Setting {attr}...') ... setattr(self, attr, value) ... >>> sys.modules[__name__].__class__ = VerboseModule >>> sys.modules[__name__].a = 5 Setting a... <...> Setting a... Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 6, in __setattr__ File "<stdin>", line 6, in __setattr__ File "<stdin>", line 6, in __setattr__ [Previous line repeated 495 more times] File "<stdin>", line 5, in __setattr__ RecursionError: maximum recursion depth exceeded while calling a Python object Setting a...>>> Something like this can fix it: def __setattr__(self, attr, value): ... print(f'Setting {attr}...') ... super().setattr(self, attr, value) ---------- assignee: docs@python components: Documentation messages: 328966 nosy: denis-osipov, docs@python priority: normal severity: normal status: open title: Customizing module attribute access example raises RecursionError type: behavior versions: Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35119> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com