(func: FunctionType, indent: int)
| 122 | |
| 123 | |
| 124 | def signature(func: FunctionType, indent: int) -> str: |
| 125 | hints = get_type_hints(func, globals()) |
| 126 | tokens = ["self"] |
| 127 | split = ",\n" + " " * indent |
| 128 | |
| 129 | saw_optional = False |
| 130 | for [name, value] in hints.items(): |
| 131 | if name == "return": |
| 132 | continue |
| 133 | positional_exception = is_positional_exception(f"{func.__name__}.{name}") |
| 134 | if saw_optional and positional_exception: |
| 135 | raise Exception( |
| 136 | "Positional exception is not first in the list " |
| 137 | + f"{func.__name__}.{name}" |
| 138 | ) |
| 139 | processed = process_type(value, True) |
| 140 | if name == "timeout": |
| 141 | processed = re.sub( |
| 142 | r"\bfloat\b", |
| 143 | "typing.Union[float, datetime.timedelta]", |
| 144 | processed, |
| 145 | ) |
| 146 | if ( |
| 147 | not positional_exception |
| 148 | and not saw_optional |
| 149 | and processed.startswith("typing.Optional") |
| 150 | ): |
| 151 | saw_optional = True |
| 152 | tokens.append("*") |
| 153 | tokens.append(f"{to_snake_case(name)}: {processed}") |
| 154 | return split.join(tokens) |
| 155 | |
| 156 | |
| 157 | def arguments(func: FunctionType, indent: int) -> str: |
no test coverage detected