[New-bugs-announce] [issue37941] python -m and runpy.run_module set different __name__ by default
Julian Berman
report at bugs.python.org
Sat Aug 24 13:59:15 EDT 2019
New submission from Julian Berman <Julian+Python.org at GrayVines.com>:
This seems brutally simple, to the point where I'm concerned I'm missing something (or have seen this issue filed elsewhere but can't find it), but `python -m` and `runpy.run_module` don't set the same __name__ -- specifically `runpy.run_module`, when given a non-package, defaults to setting __name__ to `mod_name`.
So, given package/foo.py, with the "common"
`if __name__ == "__main__":` check at the bottom, `python -m package.foo` successfully executes, but `runpy.run_module("package.foo")` exits silently, unless explicitly passed `runpy.run_module("package.foo", run_name="__main__").
[n.b. pep517.{build,check} is a specific example of such a module that advertises itself as wanting to be executed via `python -m`]
issue16737 seems related but not exactly the same from what I can tell.
----------
messages: 350387
nosy: Julian
priority: normal
severity: normal
status: open
title: python -m and runpy.run_module set different __name__ by default
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37941>
_______________________________________
More information about the New-bugs-announce
mailing list