On 23 November 2015 at 02:32, Glyph Lefkowitz <[email protected]> wrote:
> > On Nov 22, 2015, at 07:04, Adi Roiban <[email protected]> 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. > > I think that we can go with a dedicated instance check for properties... this is about the @deprecated decorator and using it together with the deprecation policy for instance members. I have created a dedicated ticket https://twistedmatrix.com/trac/ticket/8124 I still don't know how to fix it... I tried following property.__get__ and property.getter and property.fget >From what I understand of how Python works, at the time when the decorator is called, the class is not yet created / does not yet exists. This will not work class SomeClass(object): @deprecated( Version("Twisted", 16, 0, 0), 'the deferred returned by start()') @property def deferred(self): """ DEPRECATED. Deferred fired when loop stops or fails. """ return self._deferred And I should use something like this class SomeClass(object): @property def deferred(self): """ DEPRECATED. Deferred fired when loop stops or fails. """ deprecated( Version("Twisted", 16, 0, 0), 'the deferred returned by start()') return self._deferred --------- Will push the tests and will ask for help in the review queue. Thanks! -- Adi Roiban
_______________________________________________ Twisted-Python mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
