MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / getargspec

Function getargspec

tensorflow/python/util/tf_inspect.py:98–147  ·  view source on GitHub ↗

TFDecorator-aware replacement for `inspect.getargspec`. Note: `getfullargspec` is recommended as the python 2/3 compatible replacement for this function. Args: obj: A function, partial function, or callable object, possibly decorated. Returns: The `ArgSpec` that describes the sign

(obj)

Source from the content-addressed store, hash-verified

96
97
98def getargspec(obj):
99 """TFDecorator-aware replacement for `inspect.getargspec`.
100
101 Note: `getfullargspec` is recommended as the python 2/3 compatible
102 replacement for this function.
103
104 Args:
105 obj: A function, partial function, or callable object, possibly decorated.
106
107 Returns:
108 The `ArgSpec` that describes the signature of the outermost decorator that
109 changes the callable's signature, or the `ArgSpec` that describes
110 the object if not decorated.
111
112 Raises:
113 ValueError: When callable's signature can not be expressed with
114 ArgSpec.
115 TypeError: For objects of unsupported types.
116 """
117 if isinstance(obj, functools.partial):
118 return _get_argspec_for_partial(obj)
119
120 decorators, target = tf_decorator.unwrap(obj)
121
122 spec = next((d.decorator_argspec
123 for d in decorators
124 if d.decorator_argspec is not None), None)
125 if spec:
126 return spec
127
128 try:
129 # Python3 will handle most callables here (not partial).
130 return _getargspec(target)
131 except TypeError:
132 pass
133
134 if isinstance(target, type):
135 try:
136 return _getargspec(target.__init__)
137 except TypeError:
138 pass
139
140 try:
141 return _getargspec(target.__new__)
142 except TypeError:
143 pass
144
145 # The `type(target)` ensures that if a class is received we don't return
146 # the signature of its __call__ method.
147 return _getargspec(type(target).__call__)
148
149
150def _get_argspec_for_partial(obj):

Callers 2

_getfullargspecFunction · 0.85
_get_argspec_for_partialFunction · 0.85

Calls 4

_get_argspec_for_partialFunction · 0.85
_getargspecFunction · 0.85
typeFunction · 0.85
unwrapMethod · 0.80

Tested by

no test coverage detected