From ffebe06564666e0c1d66a5ecc9d37bd72bb55f32 Mon Sep 17 00:00:00 2001 From: dgw Date: Mon, 22 Apr 2019 02:46:04 -0500 Subject: [PATCH] tools: use functools.wraps in `deprecated` The way it worked before, Sphinx would output `**kwargs` as the function parameters for methods decorated with `deprecated`, instead of the real signature. Not surprising, I guess, given what the code was doing. As for why we weren't already using functools.wraps in the decorator itself, it's been around since the root commit of this repo, ten years ago, back when this project was still named "Jenni". The functools module was added in Python 2.5, but maybe this decorator was originally added before that version came out? We might never know, but let's use the modern way from now on! --- sopel/tools/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sopel/tools/__init__.py b/sopel/tools/__init__.py index 20c14a888e..7695492fa2 100644 --- a/sopel/tools/__init__.py +++ b/sopel/tools/__init__.py @@ -14,11 +14,12 @@ from __future__ import unicode_literals, absolute_import, print_function, division -import sys +import codecs +import functools import os import re +import sys import threading -import codecs import traceback from collections import defaultdict @@ -232,14 +233,13 @@ def deprecated(old): Any time a decorated function is used, a deprecation warning will be printed to the console/log-file. """ + @functools.wraps(old) def new(*args, **kwargs): print('Function %s is deprecated.' % old.__name__, file=sys.stderr) trace = traceback.extract_stack() for line in traceback.format_list(trace[:-1]): stderr(line[:-1]) return old(*args, **kwargs) - new.__doc__ = old.__doc__ - new.__name__ = old.__name__ return new