<div dir="ltr">On Tue, Aug 13, 2013 at 7:21 AM, Brett Cannon <span dir="ltr"><<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="color:rgb(80,0,80)">On Tue, Aug 13, 2013 at 12:17 AM, Eric Snow </span><span dir="ltr" style="color:rgb(80,0,80)"><<a href="mailto:ericsnowcurrently@gmail.com" target="_blank">ericsnowcurrently@gmail.com</a>></span><span style="color:rgb(80,0,80)"> wrote:</span><br>
<div class="gmail_extra"><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>On Sun, Aug 11, 2013 at 2:08 PM, Brett Cannon <span dir="ltr"><<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><br></div></div></blockquote>
</div></div></div></blockquote><div><br></div></div><div>[SNIP]</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div></div></div></blockquote><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div> ``module_repr()`` also conflicts with the same</div>
<div>method on loaders, but that workaround is not complicated since both are</div><div>methods.</div><div><br></div><div>Unfortunately, the ability to proxy does not extend to ``id()``</div>
<div>comparisons and ``isinstance()`` tests. In the case of the return value</div><div>of ``find_module()``, we accept that break in backward compatibility.</div><div>However, we will mitigate the problem with ``isinstance()`` somewhat by</div>
<div>registering ``ModuleSpec`` on the loaders in ``importlib.abc``.</div></div></div></blockquote><div><br></div></div><div>Actually, ModuleSpec doesn't even need to register; __instancecheck__ and __subclasscheck__ can just be defined and delegate by calling issubclass/isinstance on the loader as appropriate.</div>
</div></div></div></blockquote><div><br></div></div><div>Do you mean add custom versions of those methods to importlib.abc.Loader?</div></div></div></div></blockquote><div><br></div></div><div>Nope, I meant ModuleSpec because every time I have a reason to override something it's on the object and not the class and so I forget the support is the other way around. Argh.</div>
</div></div></div></blockquote><div><br></div><div>Yeah, that would make things a lot easier.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<div class="gmail_extra"><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div> That should work as well as the register approach. It won't work for all loaders but should be good enough. I was just planning on registering ModuleSpec on the loader in the setter for a `loader` property on ModuleSpec.</div>
</div></div></div></blockquote><div><br></div></div><div>But the registration is at the class level so how would that work? </div></div></div></div>
</blockquote></div><br></div><div class="gmail_extra">@property</div><div class="gmail_extra">def loader(self):</div><div class="gmail_extra"> return self._loader</div><div class="gmail_extra"><br></div><div class="gmail_extra">
@loader.setter</div><div class="gmail_extra">def loader(self, loader):</div><div class="gmail_extra"> try:</div><div class="gmail_extra"> register = loader.__class__.register</div><div class="gmail_extra"> except AttributeError:</div>
<div class="gmail_extra"> pass</div><div class="gmail_extra"> else:</div><div class="gmail_extra"> register(self.__class__)</div><div class="gmail_extra"> self._loader = loader</div><div class="gmail_extra">
<br></div><div class="gmail_extra">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.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">-eric</div></div>