[Import-SIG] Round 2 for "A ModuleSpec Type for the Import System"

Brett Cannon brett at python.org
Wed Aug 28 22:20:49 CEST 2013


On Wed, Aug 28, 2013 at 3:40 PM, Eric Snow <ericsnowcurrently at gmail.com>wrote:

>
> On Aug 28, 2013 11:27 AM, "Brett Cannon" <brett at python.org> wrote:
> > On Wed, Aug 28, 2013 at 12:04 PM, Eric Snow <ericsnowcurrently at gmail.com>
> wrote:
> >>
> >> On Wed, Aug 28, 2013 at 8:43 AM, Eric Snow <ericsnowcurrently at gmail.com>
> wrote:
> >>>
> >>> On Aug 28, 2013 3:26 AM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
> >>> > I realised that if we're going to allow mutating the spec in create,
> we're going to have to promise not to reuse them across load calls. So
> loaders can be shared, but specs can't.
> >>>
> >>> The latest version of the PEP already specifies that each module will
> have its own copy, even if the spec is otherwise the same.  Perhaps it
> should also make clear that loading_info should not be shared between
> specs.  It wouldn't hurt to also say something about allowing only one call
> to load() or something along those lines
> >>
> >> I see three options:
> >>
> >> 1. We advise against calling Modulespec.create() and ModuleSpec.load()
> more than once.
> >> 2. ModuleSpec's create() and load() programmatically disallow (or
> otherwise handle) being called more than once.
> >> 3. Dictate that Loader.create_module() must handle the case where it is
> called more than once.  Fail?  Return None?  Return the same module as
> before?
> >>
> >> I'll advocate for 3 along with making sure ModuleSpec.create()
> correctly handles the exceptional response of Loader.create_module().
>  However, the PEP does not really specify what happens when create() and
> load() are called multiple times.  That needs to be added.  I'm tempted to
> have load() simply return whatever is in sys.modules and bypass loading if
> the module is already loaded.
> >
> >
> > Isn't that the point of reload() sans the blind return? This is heading
> down the road of trying to worry about stuff that will likely never happen
> except by people trying to bypass the import system and thus are just
> asking to get screwed up. We shouldn't bend over to block or (or support
> it).
>
> I'm fine with that.  My only concern is the case where people take
> advantage of the spec methods to directly load/reload/etc. and it behaves
> in an unexpected way.
>

They shouldn't do that. =) If it is that big of a worry then the methods
could shift to importlib.abc.Loader and be completely removed from
ModuleSpec to make it very obvious they should not be trifled with unless
you know what you are doing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20130828/2a7ca946/attachment-0001.html>


More information about the Import-SIG mailing list