Brett Cannon <> 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:

It's documented through 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 

@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 <>
Python-bugs-list mailing list

Reply via email to