|
8 | 8 | .. include:: ./documentation.md |
9 | 9 | """ |
10 | 10 | import ast |
| 11 | +import enum |
11 | 12 | import importlib.machinery |
12 | 13 | import importlib.util |
13 | 14 | import inspect |
@@ -1093,21 +1094,27 @@ def _params(func_obj, annotate=False, link=None, module=None): |
1093 | 1094 | return ["..."] |
1094 | 1095 |
|
1095 | 1096 | def safe_default_value(p: inspect.Parameter): |
1096 | | - if p.default is inspect.Parameter.empty: |
| 1097 | + value = p.default |
| 1098 | + if value is inspect.Parameter.empty: |
1097 | 1099 | return p |
1098 | 1100 |
|
1099 | | - replacement = None |
1100 | | - if p.default is os.environ: |
1101 | | - replacement = 'os.environ' |
1102 | | - elif inspect.isclass(p.default): |
1103 | | - replacement = p.default.__module__ + '.' + p.default.__qualname__ |
1104 | | - elif ' at 0x' in repr(p.default): |
1105 | | - replacement = re.sub(r' at 0x\w+', '', repr(p.default)) |
1106 | | - |
1107 | | - nonlocal link |
1108 | | - if link and ('<' in repr(p.default) or '>' in repr(p.default)): |
1109 | | - import html |
1110 | | - replacement = html.escape(replacement or p.default) |
| 1101 | + replacement = next((i for i in ('os.environ', |
| 1102 | + 'sys.stdin', |
| 1103 | + 'sys.stdout', |
| 1104 | + 'sys.stderr',) |
| 1105 | + if value is eval(i)), None) |
| 1106 | + if not replacement: |
| 1107 | + if isinstance(value, enum.Enum): |
| 1108 | + replacement = str(value) |
| 1109 | + elif inspect.isclass(value): |
| 1110 | + replacement = value.__module__ + '.' + value.__qualname__ |
| 1111 | + elif ' at 0x' in repr(value): |
| 1112 | + replacement = re.sub(r' at 0x\w+', '', repr(value)) |
| 1113 | + |
| 1114 | + nonlocal link |
| 1115 | + if link and ('<' in repr(value) or '>' in repr(value)): |
| 1116 | + import html |
| 1117 | + replacement = html.escape(replacement or repr(value)) |
1111 | 1118 |
|
1112 | 1119 | if replacement: |
1113 | 1120 | class mock: |
|
0 commit comments