[patch] deprecation warnings branch

John Arbash Meinel john at arbash-meinel.com
Fri Jan 6 01:06:29 GMT 2006


Robert Collins wrote:
> On Thu, 2006-01-05 at 15:56 -0600, John Arbash Meinel wrote:
> 
>>So how does staticmethod and classmethod do it? Do they cheat because
>>they are C code? Are there any other standard decorators that we could
>>try and figure out the correct actions?
> 
> 
> I'm not sure, but thats quite possible. If you see one, tell me ;).
> 

Well, looking here:
http://www.python.org/peps/pep-0318.html

It looks like if you are decorating a function you use 'func.func_name'
to set the name. I'm not sure how this differs from func.__name__
(This is most of the way down @ 'Enforce function argument and return
types')

> 
>>I'm thinking that we probably could create a decorator function (like
>>you did with _populate_decorated), which could be used by any decorator
>>that we end up creating.
>>
>>Then we would only have to implement whatever convoluted logic once, and
>>reuse it on any decorator we create.
> 
> 
> Naturally ;)
> 
> Rob
> 

Digging into it a little bit more, I found the useful parameters:
func.func_code.co_argcount
func.func_code.co_varnames
func.func_defaults

However, trying to set any of them seems to give me 'TypeError: readonly
attribute'.

You can at least do:
=== modified file 'bzrlib/symbol_versioning.py'
--- bzrlib/symbol_versioning.py
+++ bzrlib/symbol_versioning.py
@@ -111,3 +111,4 @@
     _decorate_docstring(callable, deprecation_version, label,
                         decorated_callable)
     decorated_callable.__name__ = callable.__name__
+    decorated_callable.__module__ = callable.__module__

Which fixes up the module attribute.

Reading inspect.py, it seems like you do have to get at
func_code.co_varnames to fix these things up. Which I assume isn't
possible because the python interpreter needs them itself.

So I'm guessing that the only way we could reproduce it properly would
be to use some sort of dynamically generated string, which then uses
eval() to create the object. I always avoid using eval() myself.

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060105/38e366bf/attachment.pgp 


More information about the bazaar mailing list