Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2498d9e

Browse files
committed
Issue #19272: slight clarification of pickle docs with regard to lambda.
1 parent 63c141c commit 2498d9e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Doc/library/pickle.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ The following types can be pickled:
384384

385385
* tuples, lists, sets, and dictionaries containing only picklable objects
386386

387-
* functions defined at the top level of a module
387+
* functions defined at the top level of a module (using :keyword:`def`, not
388+
:keyword:`lambda`)
388389

389390
* built-in functions defined at the top level of a module
390391

@@ -402,7 +403,7 @@ raised in this case. You can carefully raise this limit with
402403
:func:`sys.setrecursionlimit`.
403404

404405
Note that functions (built-in and user-defined) are pickled by "fully qualified"
405-
name reference, not by value. This means that only the function name is
406+
name reference, not by value. [#]_ This means that only the function name is
406407
pickled, along with the name of the module the function is defined in. Neither
407408
the function's code, nor any of its function attributes are pickled. Thus the
408409
defining module must be importable in the unpickling environment, and the module
@@ -850,6 +851,9 @@ The following example reads the resulting pickled data. ::
850851

851852
.. [#] Don't confuse this with the :mod:`marshal` module
852853
854+
.. [#] This is why :keyword:`lambda` functions cannot be pickled: all
855+
:keyword:`lambda` functions share the same name: ``<lambda>``.
856+
853857
.. [#] The exception raised will likely be an :exc:`ImportError` or an
854858
:exc:`AttributeError` but it could be something else.
855859

0 commit comments

Comments
 (0)