[Twisted-Python] How to get the class of the wrapped fget/fset property methods

Glyph Lefkowitz glyph at twistedmatrix.com
Sun Nov 22 17:32:38 MST 2015


> On Nov 22, 2015, at 07:04, Adi Roiban <adi at roiban.ro> wrote:
> 
> The @deprecated decorator (at leas on py2.7) does not work when paired @property
> 
> For deprecated instance variables, our deprecation policy recommend converting them into properties and emitted the  warning from there.
> It would be nice if we could use the standard @deprecated decorator here.
> 
> The problem is that when property are used the fget/fset are received by the @deprecated wrapper as functions and not as methods
> 
> Is there a way to get the class in which a property is defined... or there is no way to use the @deprecated decorator with the @property .. and we should create a dedicated deprecatedMember method which is called as a normal method. 

If you care about inheritance, the implementation is a little bit tricky, because you have to manually walk the class hierarchy looking for the attribute.  But conceptually it's pretty simple: just look at the type of 'oself' in the __get__ method of the returned descriptor.

Right now, @deprecated is hard-coded to assume a function, but it could be repurposed to work with specific other descriptor types reasonably easily.  Arbitrary descriptors might be hard, because it's not clear when to emit the message, but specific types like @property should be pretty straightforward with an instance check.

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20151122/312f34e2/attachment-0002.html>


More information about the Twisted-Python mailing list