[issue37941] python -m and runpy.run_module set different __name__ by default

Nick Coghlan report at bugs.python.org
Tue Sep 3 03:41:26 EDT 2019


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Yes, this is deliberate. From the run_module documentation: "__name__ is set to run_name if this optional argument is not None, to mod_name + '.__main__' if the named module is a package and to the mod_name argument otherwise."

This allows arbitrary code to be executed to populate a namespace, but you have to explicitly opt-in to having a second pseudo-__main__ module run in the same process (with all the potential pickle compatibility issues that doing so creates).

----------
resolution:  -> not a bug

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37941>
_______________________________________


More information about the Python-bugs-list mailing list