
On 29Jul2021 15:58, Paul Moore <p.f.moore@gmail.com> wrote:
On Thu, 29 Jul 2021 at 15:39, Leonardo Freua <leonardo.batista.freua@gmail.com> wrote:
Would it be interesting to create a @deprecated decorator to avoid adding warnings.warn("deprecation message", DeprecationWarning, stacklevel=2) in methods body?
I don't see the value personally.
I do. Like various others here I wrote myself such a decorator long ago. It was named @OBSOLETE and was by no means as complete as, say, the Deprecated PyPI module. But the use case was the same: @OBSOLETE def old_func(): A decorator is concise and right up front in the code. As others have mentioned, it becomes easy for tooling to see or use. (Not mine, it is a miracle of crudity, just issuing warning() calls when the function is first called from some place - it does at least say where the call was made from.) [...]
Why would it be "interesting"? I don't see any practical advantage, and as soon as you need any form of logic you have to rewrite, so why bother?
That's the case for any presupplied convenience. But it covers off a lot of the common cases to my mind. The idea's a definite +1 from me. Cheers, Cameron Simpson <cs@cskk.id.au>