Message110470
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' |
|
Date |
User |
Action |
Args |
2010-07-16 18:39:26 | pitrou | set | recipients:
+ pitrou, tim.peters, barry, nnorwitz, terry.reedy, amaury.forgeotdarc, mark.dickinson, belopolsky, alexandre.vassalotti, benjamin.peterson |
2010-07-16 18:39:26 | pitrou | set | messageid: <1279305566.24.0.0133539323324.issue3657@psf.upfronthosting.co.za> |
2010-07-16 18:39:24 | pitrou | link | issue3657 messages |
2010-07-16 18:39:23 | pitrou | create | |
|