This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amaury.forgeotdarc
Recipients amaury.forgeotdarc, barry, benjamin.peterson, nnorwitz
Date 2008-09-12.11:34:57
SpamBayes Score 4.3835417e-08
Marked as misclassified No
Message-id <1221219352.51.0.256963452875.issue3657@psf.upfronthosting.co.za>
In-reply-to
Content
The explanation is actually simple, do not blame bsddb :-)

random.random is a built-in method, so its __module__ attribute is not
set. To find it, pickle.whichmodule loops through all sys.modules, and
pick the first one that contains the function.

I reproduced the problem with a simple file:
    # someModule.py
    from random import random

then, start python and:
>>> import someModule, random, pickle
>>> pickle.dumps(random.random, 0)
'csomeModule\nrandom\np0\n.'

You may have to change the name of "someModule", to be sure that it
appears before "random" in sys.modules. Tested on Windows and x86_64 Linux.

To correct this, one direction would be to search only built-in or
extension modules; for bound methods (random.random.__self__ is not
None), try to dump separately the instance and the method name (but
getattr(random._inst, 'random') is not random.random).
Or simply change the test...
History
Date User Action Args
2008-09-12 11:35:52amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc, barry, nnorwitz, benjamin.peterson
2008-09-12 11:35:52amaury.forgeotdarcsetmessageid: <1221219352.51.0.256963452875.issue3657@psf.upfronthosting.co.za>
2008-09-12 11:34:58amaury.forgeotdarclinkissue3657 messages
2008-09-12 11:34:57amaury.forgeotdarccreate