You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warning of utils.deprecated for properties is ugly #8113
The contributor's guide recommends using the deprecated decorator for attributes as follows:
@property@deprecated("Attribute labels_ was deprecated in version 0.13 and ""will be removed in 0.15. Use 'classes_' instead")deflabels_(self):
returnself.classes_
However the warning produced begins "Function labels_ is deprecated; Attribute labels_ was deprecated ...". This is ugly. It should just say "Attribute labels_ is deprecated; ...".
We should either:
remove the boilerplate "Function x is deprecated" as I think we're not counting on it being there in our deprecation messages elsewhere
handle explicitly the case where deprecated decorates a property
(No doubt futurepast aspires to do all of this right.)
If you change the uses from
@Property@deprecated
def x
to
@deprecated@Property
def x
you should be able to test using isinstance more easily.
Also, refer to it as "Attribute" rather than "Property".
On 26 December 2016 at 02:25, Dorozhko Anton ***@***.***> wrote:
I tried to handle property explicitly. It is ugly but works. What do you
think?
def _decorate_fun(self, fun):
"""Decorate function fun"""
msg = " %s is deprecated" % fun.__name__
if self.extra:
msg += "; %s" % self.extra
@functools.wraps(fun)
def wrapped(*args, **kwargs):
def ismethod(f): // check that our function is method
spec = inspect.getfullargspec(f)
return 'self' in spec.args
if ismethod(fun):
// find all properties
properties = inspect.getmembers(args[0].__class__, lambda o: isinstance(o, property))
properties_names = [x[0] for x in properties]
if fun.__name__ in properties_names:
entity = "Property"
else:
entity = "Function"
warnings.warn(entity + msg, category=None)
return fun(*args, **kwargs)
return wrapped
and I have checked on small example
class TestObject:...
@deprecated("depricated method")
def hello(self):
pass
@Property@deprecated("depricated property")
def name(self):
"""Get name"""
return self._name...
output:
test/deprecation.py:98: UserWarning: Property name is deprecated; depricated property/test/deprecation.py:98: UserWarning: Function hello is deprecated; depricated method
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8113 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz61vwmpffDSC4GagZ1vfT_esLyHBJks5rLorpgaJpZM4LVNZk>
.
Hello @jnothman, In my opinion both part(i.e deprecated(property(funct.)) & property(deprecated(funct.)) ) have to be handled separately.
Order of execution of both is reversed:
@Property @deprecated
Method()
In this case first decorated class object is created,than it becomes property.Object which is passed to __ call __(in class deprecated in decorating.py) looks like a method.So this part should be handled in _decorate_fun()(line 62 in decorating.py)
How to detect a method is property or not?
from args(passed to method) we can get self(i.e object of class) and from that object through inspect module we can get all the property of that class.Now we have to check if any function name in property(i.e fget, fset, fdel) matches with with the name of function passed to decorator for ever property. If match is found than it is a prperty otherwise a method.
@deprecated @Property
Method()
In this case method get converted to property first and than deprecated object is created. So object which is passed to decorator can be in investigated at that time that it is a method or property in __ call __() itself.
Sorry for the comment, as I'm a beginner that's why I did not know when and where to comment. I thought that this issue still needs a contributor so I proposed a solution.
Sorry this issue had retained its "Needs Contributor" label despite @Dorozhko-Anton proposing a PR. I also wrote the incorrect PR above, should have been #8113 (as github cross-references above too). I have not had the time to look at your approach, but would welcome comment at that pull-request.
Activity
Dorozhko-Anton commentedon Dec 24, 2016
Can I get this one for a start?
jnothman commentedon Dec 25, 2016
I'm not sure there is consensus about the solution, but if you understand the problem well, you should be able to come up with a persuasive solution.
Dorozhko-Anton commentedon Dec 25, 2016
I tried to handle
propertyexplicitly. It is ugly but works. What do you think?and I have checked on small example
output:
jnothman commentedon Dec 25, 2016
Dorozhko-Anton commentedon Dec 26, 2016
I was thinking about that but it will brake
propertyMay be there is a workaround by returning property from deprecated wrapper
Akshay0724 commentedon Jan 5, 2017
Hello @jnothman, In my opinion both part(i.e deprecated(property(funct.)) & property(deprecated(funct.)) ) have to be handled separately.
Order of execution of both is reversed:
@Property
@deprecated
Method()
In this case first decorated class object is created,than it becomes property.Object which is passed to __ call __(in class deprecated in decorating.py) looks like a method.So this part should be handled in _decorate_fun()(line 62 in decorating.py)
How to detect a method is property or not?
from args(passed to method) we can get self(i.e object of class) and from that object through inspect module we can get all the property of that class.Now we have to check if any function name in property(i.e fget, fset, fdel) matches with with the name of function passed to decorator for ever property. If match is found than it is a prperty otherwise a method.
@deprecated
@Property
Method()
In this case method get converted to property first and than deprecated object is created. So object which is passed to decorator can be in investigated at that time that it is a method or property in __ call __() itself.
I'd like to work in this issue if you allow me .
Akshay0724 commentedon Jan 5, 2017
I have implemented a basic solution to this problem in notebook-
https://github.com/Akshay0724/soft/blob/master/Depricate.ipynb
Please correct me if I'm wrong.
jnothman commentedon Jan 5, 2017
Work is underway at #8113, @Akshay0724. How do your comments compare?
Akshay0724 commentedon Jan 6, 2017
Sorry for the comment, as I'm a beginner that's why I did not know when and where to comment. I thought that this issue still needs a contributor so I proposed a solution.
jnothman commentedon Jan 7, 2017
Sorry this issue had retained its "Needs Contributor" label despite @Dorozhko-Anton proposing a PR. I also wrote the incorrect PR above, should have been #8113 (as github cross-references above too). I have not had the time to look at your approach, but would welcome comment at that pull-request.