Skip to content

Commit a7ec072

Browse files
committed
#5370: doc update about unpickling objects with custom __getattr__ etc. methods.
1 parent 1956d5c commit a7ec072

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Doc/library/pickle.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ Pickling and unpickling normal class instances
458458
For :term:`new-style class`\es, if :meth:`__getstate__` returns a false
459459
value, the :meth:`__setstate__` method will not be called.
460460

461+
.. note::
462+
463+
At unpickling time, some methods like :meth:`__getattr__`,
464+
:meth:`__getattribute__`, or :meth:`__setattr__` may be called upon the
465+
instance. In case those methods rely on some internal invariant being
466+
true, the type should implement either :meth:`__getinitargs__` or
467+
:meth:`__getnewargs__` to establish such an invariant; otherwise, neither
468+
:meth:`__new__` nor :meth:`__init__` will be called.
469+
461470

462471
Pickling and unpickling extension types
463472
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)