Alejandro Gonzalez <alejandro...@gmail.com> added the comment:

>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?

----------

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

Reply via email to