Skip to content

Commit

Permalink
tools: use functools.wraps in deprecated
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
dgw committed Apr 22, 2019
1 parent 0ad35e5 commit ffebe06
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sopel/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down

0 comments on commit ffebe06

Please sign in to comment.