|
35 | 35 |
|
36 | 36 | import collections |
37 | 37 | import inspect |
| 38 | +from inspect import getfullargspec |
38 | 39 | import itertools |
39 | 40 | import operator |
40 | 41 | import re |
41 | 42 | import sys |
42 | 43 |
|
43 | 44 | __version__ = '4.0.10' |
44 | 45 |
|
45 | | -if sys.version_info >= (3,): |
46 | | - from inspect import getfullargspec |
47 | 46 |
|
| 47 | +def get_init(cls): |
| 48 | + return cls.__init__ |
48 | 49 |
|
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 |
68 | | - |
69 | | - |
70 | | - def get_init(cls): |
71 | | - return cls.__init__.__func__ |
72 | 50 |
|
73 | 51 | # getargspec has been deprecated in Python 3.5 |
74 | 52 | ArgSpec = collections.namedtuple( |
@@ -113,26 +91,21 @@ def __init__(self, func=None, name=None, signature=None, |
113 | 91 | setattr(self, a, getattr(argspec, a)) |
114 | 92 | for i, arg in enumerate(self.args): |
115 | 93 | 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) |
| 94 | + allargs = list(self.args) |
| 95 | + allshortargs = list(self.args) |
| 96 | + if self.varargs: |
| 97 | + allargs.append('*' + self.varargs) |
| 98 | + allshortargs.append('*' + self.varargs) |
| 99 | + elif self.kwonlyargs: |
| 100 | + allargs.append('*') # single star syntax |
| 101 | + for a in self.kwonlyargs: |
| 102 | + allargs.append('%s=None' % a) |
| 103 | + allshortargs.append('%s=%s' % (a, a)) |
| 104 | + if self.varkw: |
| 105 | + allargs.append('**' + self.varkw) |
| 106 | + allshortargs.append('**' + self.varkw) |
| 107 | + self.signature = ', '.join(allargs) |
| 108 | + self.shortsignature = ', '.join(allshortargs) |
136 | 109 | self.dict = func.__dict__.copy() |
137 | 110 | # func=None happens when decorating a caller |
138 | 111 | if name: |
|
0 commit comments