Re: Round 2 for "A ModuleSpec Type for the Import System"

Eric Snow <[email protected]>
Newsgroups gmane.comp.python.import
Message-ID <CALFfu7C=AfPdBs+JQwng40kD539A3GouZpA2EHhmJm5-Jk3K6Q@mail.gmail.com>
On Tue, Aug 13, 2013 at 7:16 PM, Nick Coghlan <[email protected]> wrote:

> On 13 Aug 2013 18:48, "Eric Snow" <[email protected]> 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

_______________________________________________
Import-SIG mailing list
[email protected]
http://mail.python.org/mailman/listinfo/import-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.