laurent-laporte-pro / deprecated

Python @deprecated decorator to deprecate old python classes, functions or methods.
MIT License
305 stars 34 forks source link

Deprecate @property #47

Closed glensc closed 2 years ago

glensc commented 3 years ago

Expected Behavior

Tell us what should happen.


    @deprecated(reason="Use .guid.provider")
    @property
    def provider(self):
        return self.guid.provider

Actual Behavior

Tell us what happens instead.

  File "/Users/glen/scm/plex/PlexTraktSync/plex_trakt_sync/plex_api.py", line 126, in PlexLibraryItem
    def provider(self):
  File "/Users/glen/scm/plex/PlexTraktSync/.direnv/python-3.9.5/lib/python3.9/site-packages/deprecated/classic.py", line 261, in deprecated
    raise TypeError(repr(type(args[0])))
TypeError: <class 'property'>

Environment

tantale commented 3 years ago

Actually, you can't use @deprecated on a property but a function, like this:

>>> from deprecated.classic import deprecated
>>> class Foo(object):
...     @property
...     @deprecated(reason="something has changed", version="1.2.8")
...     def foo(self):
...         return "hi"
... 
>>> f = Foo()
>>> f.foo
__main__:1: DeprecationWarning: Call to deprecated function (or staticmethod) foo. (something has changed) -- Deprecated since version 1.2.8.
'hi'

Anyway, if you have an idea to implement that, don't hesitate to do a PR.

Also, deprecating a descriptor is a similar subject…

glensc commented 3 years ago

Yes, swapping @property and @deprecated order solved the problem.

For my sake, this issue can be closed.