[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-18 Thread Roundup Robot
Roundup Robot added the comment: New changeset d103ba56710e by Ethan Furman in branch 'default': Issue #19272: slight clarification of pickle docs with regard to lambda. http://hg.python.org/cpython/rev/d103ba56710e -- nosy: +python-dev ___ Python

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-18 Thread Ethan Furman
Ethan Furman added the comment: Added some clarification to the docs to make it clearer that lambda functions cannot be pickled. Facundo [1], if you want to pursue being able to pickle lambda functions please open an enhancement issue. Some of the questions that come to mind: 1) for a

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-17 Thread Ethan Furman
Changes by Ethan Furman et...@stoneleaf.us: -- keywords: +patch Added file: http://bugs.python.org/file32155/issue19272.stoneleaf.01.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19272

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Facundo Batista
New submission from Facundo Batista: This is ok: Python 3.4.0a3+ (default:86af5991c809, Oct 13 2013, 16:42:52) ... import pickle def f(): ... pass ... pickle.dumps(f) b'\x80\x03c__main__\nf\nq\x00.' However, when trying to pickle a lambda, it fails: pickle.dumps(lambda:

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: Functions are pickled by name, not by code. Unpickling will only work if a function with the same name is present in in the same module (__main__ in your example) This is why pickling a lambda won't work: they have no individual names. -- nosy:

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Jesús Cea Avión
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19272 ___ ___ Python-bugs-list mailing list

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Jesús Cea Avión
Jesús Cea Avión added the comment: Would be interesting to be able to pickle function.__code__. Although, thinking about this, it would be not portable between Python releases, something that pickle guarantee. Thoughs? -- ___ Python tracker

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Ethan Furman
Ethan Furman added the comment: According to the docs[1]: 12.1.4. What can be pickled and unpickled? The following types can be pickled: - None, True, and False - integers, floating point numbers, complex numbers - strings, bytes, bytearrays - tuples, lists, sets, and

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Facundo Batista
Facundo Batista added the comment: Ethan, lambda functions are included in functions defined at the top level of a module. Probably we should note there something like except lambdas, because function pickling is by name, not by code. -- ___

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Facundo Batista
Facundo Batista added the comment: Jesús, Amaury: What if pickle would assign a random unique name to the lambda (like, an UUID) so it can be pickled and unpickled? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19272

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Ethan Furman
Ethan Furman added the comment: Yeah, that one line should say, named functions defined at the top level of a module. The following three paragraphs do, however, mention named several times. Sounds like a doc issue. -- ___ Python tracker

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Ethan Furman
Ethan Furman added the comment: The problem with a randam unique name is making sure you get the same random unique name across different runs, different pythons, and different orders of execution. -- ___ Python tracker rep...@bugs.python.org

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread R. David Murray
R. David Murray added the comment: So don't make it random, use a hash of the code object :) (I'm not sure I'm serious, the thought just popped into my head...) -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Jesús Cea Avión
Jesús Cea Avión added the comment: Lambdas are anonymous functions, by definition. And, usually, they are not top level functions, but defined inside others. If at your top level (module) you do: a = lambda x: 2*x You don't have an anonymous function, but a function called a. You can argue

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Ethan Furman
Ethan Furman added the comment: From the pickle docs: = Note that functions (built-in and user-defined) are pickled by “fully qualified” name reference, not by value. This means that only the function name is pickled, along

[issue19272] Can't pickle lambda (while named functions are ok)

2013-10-16 Thread Ethan Furman
Ethan Furman added the comment: Jesús Cea Avión added the comment: If at your top level (module) you do: a = lambda x: 2*x You don't have an anonymous function, but a function called a. Actually, you do have an anonymous function, which happens to be bound to the name a. Compare: