| 214 | return '', '\n'.join(lines) |
| 215 | |
| 216 | def _getargspec(object): |
| 217 | try: |
| 218 | signature = inspect.signature(object, annotation_format=Format.STRING) |
| 219 | if signature: |
| 220 | name = getattr(object, '__name__', '') |
| 221 | # <lambda> function are always single-line and should not be formatted |
| 222 | max_width = (80 - len(name)) if name != '<lambda>' else None |
| 223 | return signature.format(max_width=max_width, quote_annotation_strings=False) |
| 224 | except (ValueError, TypeError): |
| 225 | argspec = getattr(object, '__text_signature__', None) |
| 226 | if argspec: |
| 227 | if argspec[:2] == '($': |
| 228 | argspec = '(' + argspec[2:] |
| 229 | if getattr(object, '__self__', None) is not None: |
| 230 | # Strip the bound argument. |
| 231 | m = re.match(r'\(\w+(?:(?=\))|,\s*(?:/(?:(?=\))|,\s*))?)', argspec) |
| 232 | if m: |
| 233 | argspec = '(' + argspec[m.end():] |
| 234 | return argspec |
| 235 | return None |
| 236 | |
| 237 | def classname(object, modname): |
| 238 | """Get a class name and qualify it with a module name if necessary.""" |