[MERGE] Improve decorators when necessary
John Arbash Meinel
john at arbash-meinel.com
Thu Jan 25 15:43:05 GMT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Martin Pool wrote:
>> In testing the difference is 300ms for bzr --version with the new
>> decorators versus 270ms without them. So the fact that they add 30ms to
>> startup time is significant, and worth the effort of avoiding it.
> Very nice.
>> -def needs_read_lock(unbound):
>> +def _get_parameters(func):
>> + """Recreate the parameters for a function using introspection.
>> + :return: (function_params, passed_params)
>> + function_params is the list of parameters to the original function.
>> + This is something like "a, b, c=None, d=1"
>> + passed_params is how you would pass the parameters to a new function.
>> + This is something like "a=a, b=b, c=c, d=d"
>> + """
> When I first read the docstring, it was not clear to me that you were
> returning strings containing python source code, rather than a
> structured representation.
I'll clean it up. At one point it was something slightly different,
before I found the functions in 'inspect' I was doing it all manually.
>> + global _inspect
>> + if _inspect is None:
>> + import inspect
>> + _inspect = inspect
> Is this to avoid the overhead of running the import statement each time
> this method is entered?
That was the thought. I have a few options:
1) 'import inspect' at the top. The problem is inspect is one of the
files we *don't* want if we can help it. (Hence the
'inspect_for_copy.py' that I wrote).
2) lazy_import('import inspect'). That requires making decorators depend
on lazy_import. And I was trying to keep dependencies minimal. This
would certainly be an alternative, though.
3) 'import inspect' inside the function. I thought we found that to be a
Thanks. I'll definitely clean up the doc before submitting. But what are
your feelings about the 'import inspect' stuff?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the bazaar