Opened 13 years ago

Last modified 10 years ago

#8561 new enhancement

Implement PicklableFunction(interactive_function)

Reported by: nthiery Owned by: nthiery
Priority: major Milestone:
Component: pickling Keywords: Pickling, lambda, interactively defined functions
Cc: sage-combinat Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


Extend sage.misc.fpickle.pyx with a PicklableFunction? class wrapping interactively defined (simple) functions to make them picklable:

    sage: f = lambda x: x^2
    sage: loads(dumps(f))
    Traceback (most recent call last):
      File "<ipython console>", line 1, in <module>
      File "sage_object.pyx", line 792, in sage.structure.sage_object.dumps (sage/structure/sage_object.c:8357)
    PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

    sage: f = PicklableFunction(f)
    sage: f(3)
    sage: f == loads(dumps(f))

Change History (2)

comment:1 Changed 13 years ago by nthiery

Owner: changed from was to nthiery

comment:2 Changed 10 years ago by nbruin

See #11845 for some code in this direction and for warnings why this should never be allowed in "standard" pickles.

Note: See TracTickets for help on using tickets.