Re: PEP 420: Implicit Namespace Packages

Brett Cannon <[email protected]>
Newsgroups gmane.comp.python.import
Message-ID <CAP1=2W5jDJ0enZRkBxcMfQZMj5ErNE5ksxzaLNHwUyuGmouOng@mail.gmail.com>
On Wed, May 2, 2012 at 3:28 PM, Eric V. Smith <[email protected]> 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.

_______________________________________________
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.