Show More
@@ -362,7 +362,7 b' class Inspector(Colorable):' | |||||
362 | If any exception is generated, None is returned instead and the |
|
362 | If any exception is generated, None is returned instead and the | |
363 | exception is suppressed.""" |
|
363 | exception is suppressed.""" | |
364 | try: |
|
364 | try: | |
365 |
hdef = |
|
365 | hdef = _render_signature(signature(obj), oname) | |
366 | return cast_unicode(hdef) |
|
366 | return cast_unicode(hdef) | |
367 | except: |
|
367 | except: | |
368 | return None |
|
368 | return None | |
@@ -1018,42 +1018,42 b' class Inspector(Colorable):' | |||||
1018 | page.page('\n'.join(sorted(search_result))) |
|
1018 | page.page('\n'.join(sorted(search_result))) | |
1019 |
|
1019 | |||
1020 |
|
1020 | |||
1021 |
|
|
1021 | def _render_signature(obj_signature, obj_name): | |
1022 |
|
|
1022 | """ | |
1023 |
|
|
1023 | This was mostly taken from inspect.Signature.__str__. | |
1024 |
|
|
1024 | Look there for the comments. | |
1025 |
|
|
1025 | The only change is to add linebreaks when this gets too long. | |
1026 |
|
|
1026 | """ | |
1027 |
|
|
1027 | result = [] | |
1028 |
|
|
1028 | pos_only = False | |
1029 |
|
|
1029 | kw_only = True | |
1030 |
|
|
1030 | for param in obj_signature.parameters.values(): | |
1031 |
|
|
1031 | if param.kind == _POSITIONAL_ONLY: | |
1032 |
|
|
1032 | pos_only = True | |
1033 |
|
|
1033 | elif pos_only: | |
1034 | result.append('/') |
|
|||
1035 | pos_only = False |
|
|||
1036 |
|
||||
1037 | if param.kind == _VAR_POSITIONAL: |
|
|||
1038 | kw_only = False |
|
|||
1039 | elif param.kind == _KEYWORD_ONLY and kw_only: |
|
|||
1040 | result.append('*') |
|
|||
1041 | kw_only = False |
|
|||
1042 |
|
||||
1043 | result.append(str(param)) |
|
|||
1044 |
|
||||
1045 | if pos_only: |
|
|||
1046 | result.append('/') |
|
1034 | result.append('/') | |
|
1035 | pos_only = False | |||
1047 |
|
1036 | |||
1048 | # add up name, parameters, braces (2), and commas |
|
1037 | if param.kind == _VAR_POSITIONAL: | |
1049 | if len(obj_name) + sum(len(r) + 2 for r in result) > 75: |
|
1038 | kw_only = False | |
1050 | # This doesn’t fit behind “Signature: ” in an inspect window. |
|
1039 | elif param.kind == _KEYWORD_ONLY and kw_only: | |
1051 | rendered = '{}(\n{})'.format(obj_name, ''.join(' {},\n'.format(result))) |
|
1040 | result.append('*') | |
1052 | else: |
|
1041 | kw_only = False | |
1053 | rendered = '{}({})'.format(obj_name, ', '.join(result)) |
|
1042 | ||
|
1043 | result.append(str(param)) | |||
|
1044 | ||||
|
1045 | if pos_only: | |||
|
1046 | result.append('/') | |||
|
1047 | ||||
|
1048 | # add up name, parameters, braces (2), and commas | |||
|
1049 | if len(obj_name) + sum(len(r) + 2 for r in result) > 75: | |||
|
1050 | # This doesn’t fit behind “Signature: ” in an inspect window. | |||
|
1051 | rendered = '{}(\n{})'.format(obj_name, ''.join(' {},\n'.format(result))) | |||
|
1052 | else: | |||
|
1053 | rendered = '{}({})'.format(obj_name, ', '.join(result)) | |||
1054 |
|
1054 | |||
1055 |
|
|
1055 | if obj_signature.return_annotation is not _empty: | |
1056 |
|
|
1056 | anno = formatannotation(obj_signature.return_annotation) | |
1057 |
|
|
1057 | rendered += ' -> {}'.format(anno) | |
1058 |
|
1058 | |||
1059 |
|
|
1059 | return rendered |
General Comments 0
You need to be logged in to leave comments.
Login now