[issue25791] Raise an ImportWarning when __spec__.parent/__package__ isn't defined for a relative import

Nick Coghlan report at bugs.python.org
Fri Jan 15 23:43:41 EST 2016


Nick Coghlan added the comment:

Favouring __spec__.parent over __package__ will break the documented workaround in PEP 366 for enabling explicit relative imports from __main__ even when a module is run directly instead of via -m:

    if __name__ == "__main__" and __package__ is None:
        __package__ = "expected.package.name"

It may be that workaround is something we *want* to break (as per http://bugs.python.org/issue21762#msg258332 ), but if so, it's at least worthy of a porting note in the What's New document.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25791>
_______________________________________


More information about the Python-bugs-list mailing list