Message315635
@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. |
|
Date |
User |
Action |
Args |
2018-04-23 00:22:12 | brett.cannon | set | recipients:
+ brett.cannon, barry, rhettinger, ncoghlan, pitrou, pmpp, eric.snow |
2018-04-23 00:22:11 | brett.cannon | set | messageid: <1524442931.96.0.682650639539.issue33277@psf.upfronthosting.co.za> |
2018-04-23 00:22:11 | brett.cannon | link | issue33277 messages |
2018-04-23 00:22:09 | brett.cannon | create | |
|