| 3213 | return '<{} {}>'.format(self.__class__.__name__, self) |
| 3214 | |
| 3215 | def __str__(self): |
| 3216 | result = [] |
| 3217 | render_pos_only_separator = False |
| 3218 | render_kw_only_separator = True |
| 3219 | for param in self.parameters.values(): |
| 3220 | formatted = str(param) |
| 3221 | |
| 3222 | kind = param.kind |
| 3223 | |
| 3224 | if kind == _POSITIONAL_ONLY: |
| 3225 | render_pos_only_separator = True |
| 3226 | elif render_pos_only_separator: |
| 3227 | # It's not a positional-only parameter, and the flag |
| 3228 | # is set to 'True' (there were pos-only params before.) |
| 3229 | result.append('/') |
| 3230 | render_pos_only_separator = False |
| 3231 | |
| 3232 | if kind == _VAR_POSITIONAL: |
| 3233 | # OK, we have an '*args'-like parameter, so we won't need |
| 3234 | # a '*' to separate keyword-only arguments |
| 3235 | render_kw_only_separator = False |
| 3236 | elif kind == _KEYWORD_ONLY and render_kw_only_separator: |
| 3237 | # We have a keyword-only parameter to render and we haven't |
| 3238 | # rendered an '*args'-like parameter before, so add a '*' |
| 3239 | # separator to the parameters list ("foo(arg1, *, arg2)" case) |
| 3240 | result.append('*') |
| 3241 | # This condition should be only triggered once, so |
| 3242 | # reset the flag |
| 3243 | render_kw_only_separator = False |
| 3244 | |
| 3245 | result.append(formatted) |
| 3246 | |
| 3247 | if render_pos_only_separator: |
| 3248 | # There were only positional-only parameters, hence the |
| 3249 | # flag was not reset to 'False' |
| 3250 | result.append('/') |
| 3251 | |
| 3252 | rendered = '({})'.format(', '.join(result)) |
| 3253 | |
| 3254 | if self.return_annotation is not _empty: |
| 3255 | anno = formatannotation(self.return_annotation) |
| 3256 | rendered += ' -> {}'.format(anno) |
| 3257 | |
| 3258 | return rendered |
| 3259 | |
| 3260 | |
| 3261 | def signature(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False): |