On Fri, Oct 10, 2008 at 9:46 PM, Terry Reedy <[EMAIL PROTECTED]> wrote: > Brett Cannon wrote: >> >> On Fri, Oct 10, 2008 at 1:45 PM, Terry Reedy <[EMAIL PROTECTED]> wrote: > >>> The advantage of the decorator version is that the compiler or module >>> loader >>> could be special cased to recognize the 'C' decorator and try it first >>> *before* using the Python version, which would serve as a backup. There >>> could be a standard version in builtins that people could replace to >>> implement non-standard loading on a particular system. To cater to other >>> implementations, the name could be something other than 'C', or we could >>> define 'C' to be the initial of "Code" (in the implementation language). >>> Either way, other implementation could start with a do-nothing "C" >>> decorator and run the file as is, then gradually replace with lower-level >>> code. >>> >> >> The decorator doesn't have to require any special casing at all >> (changing the parameters to keep the code short):: >> >> def C(module_name, want): >> def choose_version(ob): >> try: >> module = __import__(module_name, fromlist=[want]) >> return getattr(module, want) >> except (ImportError, AttributeError): >> return ob >> return choose_version >> >> The cost is purely during importation of the module and does nothing >> fancy at all and relies on stuff already available in all Python VMs. > > If I understand correctly, this decorator would only be applied *after* the > useless Python level function object was created.
Yes. > I was proposing bypassing > that step when not necessary, and I believe special casing *would* be > required for that. Yes, that would. -Brett _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com