Hi,

I've been using https://pypi.org/project/Deprecated/ for quite some time and I recommend it.

  S.


On Thu, Jul 29, 2021 at 4:39 PM Leonardo Freua <leonardo.batista.freua@gmail.com> wrote:
[Migrating from https://bugs.python.org/issue44701]

Would it be interesting to create a @deprecated decorator to avoid adding warnings.warn("deprecation message", DeprecationWarning, stacklevel=2) in methods body?

Using the decorator approach to indicate depreciation would make the methods cleaner (leaving only their responsibilities in the body) and would be easier to identify, as the cue would be close to the method signature and not mixed with the logic inside the body.

in some cases it will still be necessary to put warnings.warn (..) inside the body of functions/methods because of some message display condition, or we could also express the message display condition in the decorator in @deprecated itself. But it would be interesting to have the possibility of not putting this inside the method body. Even the decorator can come from the notices module.

Example:

(Before)

def check_metadata(self):
        """Deprecated API."""
        warn("distutils.command.register.check_metadata is deprecated, \
              use the check command instead", PendingDeprecationWarning)
        check = self.distribution.get_command_obj('check')
        check.ensure_finalized()
        check.strict = self.strict
        check.restructuredtext = 1
        check.run()

(after)

@deprecated("distutils.command.register.check_metadata is deprecated, \
        use the check command instead")
def check_metadata(self):
  """Deprecated API."""
  check = self.distribution.get_command_obj('check')
  check.ensure_finalized()
  check.strict = self.strict
  check.restructuredtext = 1
  check.run()
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/62CTVNQ2GIS4B6WUBX23K4CCCK5MCGYL/
Code of Conduct: http://python.org/psf/codeofconduct/


--
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software - http://www.abilian.com/
Chairman, National Council for Free & Open Source Software (CNLL) - http://cnll.fr/
Founder & Organiser, PyParis & PyData Paris - http://pyparis.org/http://pydata.fr/