[Python-Dev] Could these restrictions be removed?
Antoine Pitrou
solipsis at pitrou.net
Thu May 12 19:05:46 CEST 2011
On Thu, 12 May 2011 11:33:37 -0500 (CDT)
Skip Montanaro <skip at montanaro.dyndns.org> wrote:
>
> A friend at work who is new to Python wondered why this didn't work with
> pickle:
>
> class Outer:
>
> Class Inner:
>
> ...
>
> def __init__(self):
> self.i = Outer.Inner()
>
[...]
>
> I've never questions this, but I wonder, is this a fundamental restriction
> or could it be overcome with a modest amount of work?
pickle uses heuristics to try to find out the "official name" of a
class or function. It would be a matter of improving these heuristics.
There are other cases in which pickle similarly fails:
>>> pickle.dumps(random.random)
b'\x80\x03crandom\nrandom\nq\x00.'
>>> pickle.dumps(random.randint)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <class 'method'>: attribute lookup builtins.method failed
Regards
Antoine.
More information about the Python-Dev
mailing list