[Import-SIG] PEP 420: Implicit Namespace Packages

Eric V. Smith eric at trueblade.com
Wed May 2 21:28:42 CEST 2012


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.

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!).

Eric.


More information about the Import-SIG mailing list