Brett Cannon <br...@python.org> added the comment:

@Nick: We've had this discussion before about specs being a "receipt" of import 
versus not and the last time we agreed on not. :) That's why we raise a warning 
if __package__ doesn't match __spec__.parent: 
https://github.com/python/cpython/blob/d5a2377c3d70e4143bcbee4a765b3434e21f683a/Lib/importlib/_bootstrap.py#L1056-L1059

It's documented through 
https://docs.python.org/3/reference/import.html#__package__ by saying 
__package__ has to match __spec__.parent. We didn't make it stronger since we 
can't get rid of any of these attributes until Python 2.7 compatibility is no 
longer a concern. And I believe __package__/__spec__.parent is the only 
attribute whose data is in any way directly relied on in importlib which is 
being proposed for removal (e.g. __file__, __cached__, and __loader__ are just 
recorded).

@Raymond: Thanks for the teaching info. I actually opened this after running 
dir() on a module and having there be just as many module-related attributes as 
defined attributes.

@Antoine: we can keep __file__ if necessary (I was on the fence about keeping 
it to begin with). But as Barry pointed out, bugs have occurred because we now 
have two places for most of these details and people don't always know which 
one to update.

@Barry: the tricky bit is what to do if someone sets their own __getattr__() on 
a module? E.g. I just published modutil which provides a __getattr__ for lazy 
importing, so users of this would need a way to not have either function get 
stomped on by the other.

----------

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

Reply via email to