Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev
Re: PEP 420 - dynamic path computation is missing rationale
 

Index | Next | Previous | View Flat


ncoghlan at gmail

May 22, 2012, 8:39 AM


Views: 218
Permalink
Re: PEP 420 - dynamic path computation is missing rationale [In reply to]

On Wed, May 23, 2012 at 12:51 AM, Eric V. Smith <eric [at] trueblade> wrote:
> That seems like a pretty convincing example to me.
>
> Personally I'm +1 on putting dynamic computation into the PEP, at least
> for top-level namespace packages, and probably for all namespace packages.

Same here, but Guido's right that the rationale (and example) should
be clearer in the PEP itself if the feature is to be retained.

> P.S.: Here's the current code in the pep-420 branch. This code still has
> the restriction that sys.path (or parent_path in general) can't be
> replaced. I'll fix that if we decide to keep the feature.

I wonder if it would be worth exposing an importlib.LazyRef API to
make it generally easy to avoid this kind of early binding problem?

class LazyRef:
# similar API to weakref.weakref
def __init__(self, modname, attr=None):
self.modname = modname
self.attr = attr
def __call__(self):
mod = sys.modules[self.modname]
attr = self.attr
if attr is None:
return mod
return getattr(mod, attr)

Then _NamespacePath could just be defined as taking a callable that
returns the parent path:


class _NamespacePath:
   def __init__(self, name, path, parent_path, path_finder):
       self._name = name
       self._path = path
       self._parent_path = parent_path
       self._last_parent_path = tuple(parent_path)
       self._path_finder = path_finder

   def _recalculate(self):
       # If _parent_path has changed, recalculate _path
       parent_path = tuple(self._parent_path())     # Retrieve and make a copy
       if parent_path != self._last_parent_path:
           loader, new_path = self._path_finder(self._name, parent_path)
           # Note that no changes are made if a loader is returned, but we
           #  do remember the new parent path
           if loader is None:
               self._path = new_path
           self._last_parent_path = parent_path   # Save the copy
       return self._path

Even if the LazyRef idea isn't used, I still like the idea of passing
a callable in to _NamespacePath for the parent path rather than
hardcoding the "module name + attribute name" approach.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan [at] gmail   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Subject User Time
PEP 420 - dynamic path computation is missing rationale guido at python May 20, 2012, 6:33 PM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 21, 2012, 1:00 AM
        Re: PEP 420 - dynamic path computation is missing rationale guido at python May 21, 2012, 6:55 AM
    Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 21, 2012, 11:08 AM
    Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 21, 2012, 4:25 PM
    Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 21, 2012, 4:32 PM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 21, 2012, 5:32 PM
        Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 22, 2012, 10:47 AM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 22, 2012, 7:51 AM
        Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 22, 2012, 8:39 AM
    Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 22, 2012, 8:41 AM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 22, 2012, 9:31 AM
        Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 22, 2012, 1:43 PM
    Re: PEP 420 - dynamic path computation is missing rationale guido at python May 22, 2012, 11:37 AM
    Re: PEP 420 - dynamic path computation is missing rationale barry at python May 22, 2012, 3:05 PM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 22, 2012, 5:40 PM
        Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 22, 2012, 6:49 PM
        Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 22, 2012, 6:58 PM
    Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 22, 2012, 8:58 PM
    Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 22, 2012, 9:27 PM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 23, 2012, 5:31 AM
        Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 23, 2012, 6:02 AM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 23, 2012, 6:10 AM
        Re: PEP 420 - dynamic path computation is missing rationale brett at python May 23, 2012, 12:02 PM
    Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 23, 2012, 8:13 AM
    Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 23, 2012, 12:35 PM
    Re: PEP 420 - dynamic path computation is missing rationale brett at python May 23, 2012, 12:56 PM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 23, 2012, 2:29 PM
        Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 23, 2012, 5:24 PM
            Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 23, 2012, 5:58 PM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 23, 2012, 6:02 PM
        Re: PEP 420 - dynamic path computation is missing rationale pje at telecommunity May 23, 2012, 7:58 PM
        Re: PEP 420 - dynamic path computation is missing rationale ncoghlan at gmail May 23, 2012, 8:49 PM
    Re: PEP 420 - dynamic path computation is missing rationale guido at python May 24, 2012, 11:33 AM
    Re: PEP 420 - dynamic path computation is missing rationale eric at trueblade May 24, 2012, 11:42 AM
    Re: PEP 420 - dynamic path computation is missing rationale ericsnowcurrently at gmail May 24, 2012, 1:11 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.