Message 315635 - Python tracker (original) (raw)
@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.