[Python-Dev] PEP 420 - dynamic path computation is missing rationale

Barry Warsaw barry at python.org
Wed May 23 00:05:32 CEST 2012


Minor nit.

On May 22, 2012, at 04:43 PM, PJ Eby wrote:

>def declare_namespace(package_name):
>     parent, dot, tail = package_name.rpartition('.')
>     attr = '__path__'
>     if dot:
>        declare_namespace(parent)
>     else:
>        parent, attr = 'sys', 'path'
>     with importlockcontext:
>          module = sys.modules.get(package_name)

Best to use a marker object here instead of checking for None, since the
latter is a valid value for an existing entry in sys.modules.

>          if module is None:
>              module = XXX new module here
>          module.__path__ = _NamespacePath(...stuff involving 'parent' and
>'attr')

Cheers,
-Barry


More information about the Python-Dev mailing list