[Python-ideas] PEP-499: "python -m foo" should bind to both "__main__" and "foo" in sys.modules
Andrew Barnert
abarnert at yahoo.com
Sun Aug 9 07:12:02 CEST 2015
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.
More information about the Python-ideas
mailing list