(signature: str)
| 131 | |
| 132 | |
| 133 | def parsekeywordpairs(signature: str) -> dict[str, str]: |
| 134 | preamble = True |
| 135 | stack = [] |
| 136 | substack: list[str] = [] |
| 137 | parendepth = 0 |
| 138 | annotation = False |
| 139 | for token, value in Python3Lexer().get_tokens(signature): |
| 140 | if preamble: |
| 141 | if token is Token.Punctuation and value == "(": |
| 142 | # First "(" starts the list of arguments |
| 143 | preamble = False |
| 144 | continue |
| 145 | |
| 146 | if token is Token.Punctuation: |
| 147 | if value in "({[": |
| 148 | parendepth += 1 |
| 149 | elif value in ")}]": |
| 150 | parendepth -= 1 |
| 151 | elif value == ":": |
| 152 | if parendepth == -1: |
| 153 | # End of signature reached |
| 154 | break |
| 155 | elif parendepth == 0: |
| 156 | # Start of type annotation |
| 157 | annotation = True |
| 158 | |
| 159 | if (value, parendepth) in ((",", 0), (")", -1)): |
| 160 | # End of current argument |
| 161 | stack.append(substack) |
| 162 | substack = [] |
| 163 | # If type annotation didn't end before, it does now. |
| 164 | annotation = False |
| 165 | continue |
| 166 | elif token is Token.Operator and value == "=" and parendepth == 0: |
| 167 | # End of type annotation |
| 168 | annotation = False |
| 169 | |
| 170 | if value and not annotation and (parendepth > 0 or value.strip()): |
| 171 | substack.append(value) |
| 172 | |
| 173 | return {item[0]: "".join(item[2:]) for item in stack if len(item) >= 3} |
| 174 | |
| 175 | |
| 176 | def _fix_default_values(f: Callable, argspec: ArgSpec) -> ArgSpec: |
no test coverage detected