[docs] [issue35927] Intra-package References Documentation Incomplete

Nick Coghlan report at bugs.python.org
Tue Feb 12 08:17:57 EST 2019


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

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__'"

----------

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


More information about the docs mailing list