This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ADataGman, brett.cannon, docs@python, eric.snow, ncoghlan, terry.reedy
Date 2019-02-12.13:17:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549977477.88.0.425083482491.issue35927@roundup.psfhosted.org>
In-reply-to
Content
As discussed in http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#executing-the-main-module-twice and https://www.python.org/dev/peps/pep-0395/#why-are-my-imports-broken the cryptic error message here is due to the relative import being resolved based on the module name "__main__", since the submodule was executed directly, rather than the intended "sound.filter.vocoder" name that it would have when imported or executed via the "-m" switch.

It's spectacularly unobvious what's going on if you're not deeply familiar with the intricacies of main module execution, but I haven't had any great ideas for practical ways to improve the error message.

I'm not sure we currently have access to the required info at the point this error is raised, but perhaps it would be enough to add the name of the module doing the import to the error message as a reminder that directly executing scripts inside packages does weird things to import resolution?

Something like:

  "Attempted relative import beyond top-level package '__main__'"
History
Date User Action Args
2019-02-12 13:17:57ncoghlansetrecipients: + ncoghlan, brett.cannon, terry.reedy, docs@python, eric.snow, ADataGman
2019-02-12 13:17:57ncoghlansetmessageid: <1549977477.88.0.425083482491.issue35927@roundup.psfhosted.org>
2019-02-12 13:17:57ncoghlanlinkissue35927 messages
2019-02-12 13:17:57ncoghlancreate