New submission from Brett Cannon:

When you do a relative import, __package__ is used to help resolve it, but if 
it isn't defined we fall back on using __name__ and __path__. We should 
probably consider raising an ImportWarning if __package__ isn't defined so that 
some day we can consider cleaning up __import__ and its call signature to be a 
bit more sane and drop the `globals` argument. It would also help people catch 
errors where they went overboard deleting attributes off a module.

We should probably even extend it to start using __spec__.parent and then 
falling back to __package__, and only after both are found missing do we raise 
the ImportWarning about needing to use __name__ and __path__. That way 
__import__ can simply start taking in the spec of the calling module to do all 
of its work instead of having to pass all of globals().

----------
components: Interpreter Core
messages: 255838
nosy: brett.cannon, eric.snow, ncoghlan
priority: low
severity: normal
stage: test needed
status: open
title: Raise an ImportWarning when __spec__.parent/__package__ isn't defined 
for a relative import
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25791>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to