Antoine Pitrou <pit...@free.fr> added the comment:

It should be noted that, contrary to Amaury's suggestion, pickling random.seed 
fails under 3.x:

>>> pickle.dumps(random.seed)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/antoine/py3k/__svn__/Lib/pickle.py", line 1314, in dumps
    Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'method'>: attribute lookup 
builtins.method failed

Furthermore, the original problem can also be reproduced under 3.x, using 
Amaury's trick:

>>> pickle.dumps(random.random)
b'\x80\x03crandom\nrandom\nq\x00.'
>>> list(sys.modules.values())[0].random = random.random
>>> pickle.dumps(random.random)
b'\x80\x03cheapq\nrandom\nq\x00.'

I think a possible heuristic in whichmodule() would be, if __module__ is not 
found or None, to look for a __module__ attribute on __self__:

>>> random.random.__module__
>>> random.random.__self__.__module__
'random'

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue3657>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to