Skip to content

Commit 2dd7f1a

Browse files
Drop Python 2 compatibility code from bundled decorator module
The vendored decorator.py still carried Python 2/3 branching (a getfullargspec shim, formatargspec-based signature building, and the py2-only get_init variant) even though the project now requires Python >= 3.9. Removing the dead Python 2 paths leaves the Python 3 behavior unchanged. Fixes #1107 Signed-off-by: shekhargit1912 <shekharchaugule302@gmail.com>
1 parent 75603d7 commit 2dd7f1a

1 file changed

Lines changed: 18 additions & 47 deletions

File tree

prometheus_client/decorator.py

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,20 @@
3131
Decorator module, see http://pypi.python.org/pypi/decorator
3232
for the documentation.
3333
"""
34-
from __future__ import print_function
35-
3634
import collections
3735
import inspect
36+
from inspect import getfullargspec
3837
import itertools
3938
import operator
4039
import re
4140
import sys
4241

4342
__version__ = '4.0.10'
4443

45-
if sys.version_info >= (3,):
46-
from inspect import getfullargspec
47-
48-
49-
def get_init(cls):
50-
return cls.__init__
51-
else:
52-
class getfullargspec(object):
53-
"A quick and dirty replacement for getfullargspec for Python 2.X"
54-
55-
def __init__(self, f):
56-
self.args, self.varargs, self.varkw, self.defaults = \
57-
inspect.getargspec(f)
58-
self.kwonlyargs = []
59-
self.kwonlydefaults = None
60-
61-
def __iter__(self):
62-
yield self.args
63-
yield self.varargs
64-
yield self.varkw
65-
yield self.defaults
66-
67-
getargspec = inspect.getargspec
6844

45+
def get_init(cls):
46+
return cls.__init__
6947

70-
def get_init(cls):
71-
return cls.__init__.__func__
7248

7349
# getargspec has been deprecated in Python 3.5
7450
ArgSpec = collections.namedtuple(
@@ -113,26 +89,21 @@ def __init__(self, func=None, name=None, signature=None,
11389
setattr(self, a, getattr(argspec, a))
11490
for i, arg in enumerate(self.args):
11591
setattr(self, 'arg%d' % i, arg)
116-
if sys.version_info < (3,): # easy way
117-
self.shortsignature = self.signature = (
118-
inspect.formatargspec(
119-
formatvalue=lambda val: "", *argspec)[1:-1])
120-
else: # Python 3 way
121-
allargs = list(self.args)
122-
allshortargs = list(self.args)
123-
if self.varargs:
124-
allargs.append('*' + self.varargs)
125-
allshortargs.append('*' + self.varargs)
126-
elif self.kwonlyargs:
127-
allargs.append('*') # single star syntax
128-
for a in self.kwonlyargs:
129-
allargs.append('%s=None' % a)
130-
allshortargs.append('%s=%s' % (a, a))
131-
if self.varkw:
132-
allargs.append('**' + self.varkw)
133-
allshortargs.append('**' + self.varkw)
134-
self.signature = ', '.join(allargs)
135-
self.shortsignature = ', '.join(allshortargs)
92+
allargs = list(self.args)
93+
allshortargs = list(self.args)
94+
if self.varargs:
95+
allargs.append('*' + self.varargs)
96+
allshortargs.append('*' + self.varargs)
97+
elif self.kwonlyargs:
98+
allargs.append('*') # single star syntax
99+
for a in self.kwonlyargs:
100+
allargs.append('%s=None' % a)
101+
allshortargs.append('%s=%s' % (a, a))
102+
if self.varkw:
103+
allargs.append('**' + self.varkw)
104+
allshortargs.append('**' + self.varkw)
105+
self.signature = ', '.join(allargs)
106+
self.shortsignature = ', '.join(allshortargs)
136107
self.dict = func.__dict__.copy()
137108
# func=None happens when decorating a caller
138109
if name:

0 commit comments

Comments
 (0)