Re: [Python-Dev] advice needed: best approach to enabling "metamodules"?

2014年11月30日 13:16:26 -0800

On 2014年11月30日 11:15:50 -0800
Guido van Rossum <[email protected]> wrote:
> On Sun, Nov 30, 2014 at 6:15 AM, Brett Cannon <[email protected]> wrote:
> >
> > On Sat, Nov 29, 2014, 21:55 Guido van Rossum <[email protected]> wrote:
> >
> > All the use cases seem to be about adding some kind of getattr hook to
> > modules. They all seem to involve modifying the CPython C code anyway. So
> > why not tackle that problem head-on and modify module_getattro() to look
> > for a global named __getattr__ and if it exists, call that instead of
> > raising AttributeError?
> >
> > Not sure if anyone thought of it. :) Seems like a reasonable solution to
> > me. Be curious to know what the benchmark suite said the impact was.
> >
> Why would there be any impact? The __getattr__ hook would be similar to the
> one on classes -- it's only invoked at the point where otherwise
> AttributeError would be raised.
builtins are typically found by first looking up in the current globals
(module) scope, failing, and then falling back on __builtins__.
Depending on how much overhead is added to the "failing" step, there
/might/ be a performance difference. Of course, that would only occur
wherever a __getattr__ hook is defined.
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to