https://github.com/python/cpython/commit/27890edd5aa1b990b7f458bcc6c86e83fdd1aaac
commit: 27890edd5aa1b990b7f458bcc6c86e83fdd1aaac
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: AlexWaygood <[email protected]>
date: 2024-09-26T12:19:57-07:00
summary:

[3.12] Programming FAQ: Mention object.__setattr__ as a technique for 
delegation (GH-124617) (#124625)

Co-authored-by: Jelle Zijlstra <[email protected]>

files:
M Doc/faq/programming.rst

diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 55432ab79d58d3..7a86701116413b 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1613,9 +1613,16 @@ method too, and it must do so carefully.  The basic 
implementation of
            self.__dict__[name] = value
        ...
 
-Most :meth:`!__setattr__` implementations must modify
-:attr:`self.__dict__ <object.__dict__>` to store
-local state for self without causing an infinite recursion.
+Many :meth:`~object.__setattr__` implementations call 
:meth:`!object.__setattr__` to set
+an attribute on self without causing infinite recursion::
+
+   class X:
+       def __setattr__(self, name, value):
+           # Custom logic here...
+           object.__setattr__(self, name, value)
+
+Alternatively, it is possible to set attributes by inserting
+entries into :attr:`self.__dict__ <object.__dict__>` directly.
 
 
 How do I call a method defined in a base class from a derived class that 
extends it?

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to