[Python-ideas] PEP-499: "python -m foo" should bind to both "__main__" and "foo" in sys.modules

Joseph Jevnik joejev at gmail.com
Sun Aug 9 09:05:42 CEST 2015


If I have a package that defines both a __main__ and a __init__, then your
change would bind the __main__ to the name instead of the __init__. That
seems incorrect.

On Sun, Aug 9, 2015 at 1:12 AM, Andrew Barnert via Python-ideas <
python-ideas at python.org> wrote:

> On Aug 8, 2015, at 16:18, Cameron Simpson <cs at zip.com.au> wrote:
> > I think I take the line that as of PEP 451 the conanical name for a
> module is .__spec__.name. The module's .__name__ normally matches that, but
> obviously in the case of "python -m" it does not.
> >
> > As you point out, suddenly a module can appear somewhere other than
> sys.modules['__main__'] where that difference shows.
> >
> > Let's ask the associated question: who introspects module.__name__ and
> expects it to be the cononical name? For what purpose?
>
> I'd think the first place to look is code that deals directly with module
> objects and/or sys.modules--graphical debuggers, plugin frameworks, bridges
> (a la AppScript or PyObjC), etc. Especially since many of them want to
> retain compatibility with 3.3, if not 3.2, and to share as much code as
> possible with a 2.x version
>
> Of course you're probably right that there aren't too many such things,
> and they're also presumably written by people who know what they're doing
> and wouldn't have too much trouble adapting them for 3.6+ if needed.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150809/e08852ff/attachment.html>


More information about the Python-ideas mailing list