[Import-SIG] PEP 420: Implicit Namespace Packages

Brett Cannon brett at python.org
Wed May 2 21:39:47 CEST 2012


On Wed, May 2, 2012 at 3:28 PM, Eric V. Smith <eric at trueblade.com> wrote:

> On 05/02/2012 02:53 PM, Brett Cannon wrote:
>
> > You actually don't need to explicitly type-check and instead can rely on
> > duck typing::
> >
> >   if loader is None: continue
> >   elif hasattr(loader, 'load_module'): return loader
> >   else:
> >      namespace.append(loader)
> >      continue
>
> While I agree that this accomplishes the job, I don't think it's any
> more readable than the existing code:
>
>  if isinstance(loader, str):
>      namespace.append(loader)
>  elif loader:
>      return loader
>
> (with the case of None causing the code to loop)
>
> But I'm open to changing it.
>
>
I honestly don't care. I just wanted to point out to Martin that if he
wanted a more interface check over type check it's totally doable.


> As to the three return types: Given that find_module() has all of the
> information, I don't think it makes sense to add another method. And for
> backward compatibility, we need to keep the {None, loader} return types.
> If you agree that adding another method is wasteful (it will have to do
> most of the same work as find_module(), or cache its result), then I
> think adding a str return type makes the most sense.
>
> I can't foresee this ever causing an actual problem. No one is going to
> subclass a loader from str (famous last words, I know!).


Just as I know PJE is going to point out that your loader test won't work
if a loader happens to be false and thus you should do an explicit ``is not
None`` check.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20120502/1b5c946b/attachment.html>


More information about the Import-SIG mailing list