[Import-SIG] PEP 451 (ModuleSpec) round 3

Brett Cannon brett at python.org
Thu Aug 29 15:21:42 CEST 2013


On Thu, Aug 29, 2013 at 5:43 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> Just a general comment: spec and module mismatches have to be considered
> *normal*, and the module has to take precedence. Otherwise you risk
> breaking too much code.
>
> The spec is *not* authoritative in general. The only exception is that
> when __name__ ends with "__main__", pickle should be updated to look at the
> name on the spec instead.
>
> Even the attribute setting after create_module should respect custom
> settings provided by the loader.
>

I agree with this. Modules that change values during their
importation/execution will be setting __name__, __package__, etc., not
__spec__.__name__. And pre-existing code is going to change those values,
so __spec__ is definitely not definitive.

As for mutating __spec__ to match other data after execution, I don't think
that's needed. __spec__ should be viewed as a way to record what import
worked with to make the import happen, but otherwise it's there because
memory is cheap thanks to most systems not having many modules and it's
better to log stuff unnecessarily than potentially toss out useful
information.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20130829/8b5c0ac2/attachment.html>


More information about the Import-SIG mailing list