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

Eric Snow ericsnowcurrently at gmail.com
Wed Aug 14 05:18:35 CEST 2013


On Tue, Aug 13, 2013 at 7:16 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 13 Aug 2013 18:48, "Eric Snow" <ericsnowcurrently at gmail.com> wrote:
> > @property
> > def loader(self):
> >     return self._loader
> >
> > @loader.setter
> > def loader(self, loader):
> >     try:
> >         register = loader.__class__.register
> >     except AttributeError:
> >         pass
> >     else:
> >         register(self.__class__)
> >     self._loader = loader
> >
> > It's not pretty and it won't work on non-ABCs, but it's better than
> nothing.  The likelihood of someone doing an isinstance check on a loader
> seems pretty low though.  Of course, I'm planning on doing just that for
> handling of namespace packages, but that's a little different.
>
> That ends up registering ModuleSpec as an example of every loader ABC, so
> it doesn't work at all.
>
 I guess it does amount to a cheap trick, allowing isinstance() checks to
pass but not necessarily providing the appropriate APIs.

> Making the importlib ABC hooks ModuleSpec aware (so they knew to check the
> loader, not the spec) would be pretty easy, though.
>
That's what I thought Brett was recommending earlier.  I was going to
express hesitation at spreading backward-compatibility tendrils.  However,
your recommendation is probably a good idea on its own.  Several of the
collections ABCs do explicit API checks and they'd work well here too.
 I'll add this to the PEP.

-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20130813/4ce42ad3/attachment.html>


More information about the Import-SIG mailing list