Skip to content
This repository

%store raises exception when storing compiled regex #16

Closed
ipython opened this Issue May 10, 2010 · 4 comments

3 participants

IPython: interactive computing in Python Fernando Perez Thomas Kluyver
IPython: interactive computing in Python
Owner
ipython commented May 10, 2010

Original Launchpad bug 396351: https://bugs.launchpad.net/ipython/+bug/396351
Reported by: tmp-ipython (matt_ipython).

> import re
> compiled_re = re.compile(r'^(\d+)')
> %store compiled_re

AttributeError: __class__

The object "compiled_re" does in fact get pickled and is automatically restored when ipython is next launched. But code to print out user feedback is assuming that the object being stored has an attribute "class", which a compiled regular expression does not have.

I'm not sure if there is a reliable way to always get equivalent of the "name" attribute for all objects or not. In the couple cases I tried however (including for the compiled_re object), replacing:

obj.class.name

with

type(obj).name

worked. I would think that doing something like this which is not necessarily 100% reliable should be inside of a try/except block.

I'm new to iPython as of today. I'm running version "0.10.bzr.r1163".

IPython: interactive computing in Python
Owner
ipython commented May 10, 2010

[ LP comment 1 by: Ville M. Vainio, on 2009-07-07 06:32:30+00:00 ]

On Tue, Jul 7, 2009 at 7:13 AM, matt_ipython wrote:

The object "compiled_re" does in fact get pickled and is automatically
restored when ipython is next launched. But code to print out user
feedback is assuming that the object being stored has an attribute
"class", which a compiled regular expression does not have.

Yeah, it's trivial to just do the class name lookup in Try/Except.
Currently the code is:

/usr/local/lib/python2.6/dist-packages/IPython/Extensions/pspersistence.pyc
in magic_store(self, parameter_s)
178 #pickled = pickle.dumps(obj)

179             self.db[ 'autorestore/' + args[0] ] = obj

--> 180 print "Stored '%s' (%s)" % (args[0], obj.class.name)
181

Ville M. Vainio
http://tinyurl.com/vainio

Thomas Kluyver
Collaborator

%store is in quarantine for 0.11: do we plan to bring it back?

Fernando Perez
Owner

The quarantine folder isn't too big, but right now I don't think we have the manpower to port all of that. So for now I think all quarantine code means the issue is dormant.

If anyone jumps on it, that's great, but we'll have to focus on the more active parts of the code for now.

Fernando Perez
Owner

%store is back and this now actually works fine, so the issue did get fixed in the interim. Closing.

Fernando Perez fperez closed this November 27, 2011
Damián Avila damianavila referenced this issue from a commit July 30, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.