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 alegonz
Recipients abarry, alegonz, levkivskyi, serhiy.storchaka, steven.daprano
Date 2019-06-17.02:46:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
>Getting the module name from the caller's frame is an expensive operation. It is safe to set __module__ to None. In such case the pickle module is able to find the proper module containing the definition of the class.

Wow, indeed it works. I also tried it from another module other than `__main__` and it works.

Checking the source, I see the "magic" happens in pickle's `whichmodule` function when looping over `sys.modules` if `__module__` is not found. If that case, why check for `__module__` in the first place? wouldn't it be simpler to always loop over sys.modules? Is it to avoid looping over `sys.modules` whenever possible?
Date User Action Args
2019-06-17 02:46:07alegonzsetrecipients: + alegonz, steven.daprano, serhiy.storchaka, levkivskyi, abarry
2019-06-17 02:46:07alegonzsetmessageid: <>
2019-06-17 02:46:07alegonzlinkissue28869 messages
2019-06-17 02:46:07alegonzcreate