(
document: Document, locals: dict[str, Any], globals: dict[str, Any]
)
| 161 | |
| 162 | |
| 163 | def get_signatures_using_jedi( |
| 164 | document: Document, locals: dict[str, Any], globals: dict[str, Any] |
| 165 | ) -> list[Signature]: |
| 166 | script = get_jedi_script_from_document(document, locals, globals) |
| 167 | |
| 168 | # Show signatures in help text. |
| 169 | if not script: |
| 170 | return [] |
| 171 | |
| 172 | try: |
| 173 | signatures = script.get_signatures() |
| 174 | except ValueError: |
| 175 | # e.g. in case of an invalid \\x escape. |
| 176 | signatures = [] |
| 177 | except Exception: |
| 178 | # Sometimes we still get an exception (TypeError), because |
| 179 | # of probably bugs in jedi. We can silence them. |
| 180 | # See: https://github.com/davidhalter/jedi/issues/492 |
| 181 | signatures = [] |
| 182 | else: |
| 183 | # Try to access the params attribute just once. For Jedi |
| 184 | # signatures containing the keyword-only argument star, |
| 185 | # this will crash when retrieving it the first time with |
| 186 | # AttributeError. Every following time it works. |
| 187 | # See: https://github.com/jonathanslenders/ptpython/issues/47 |
| 188 | # https://github.com/davidhalter/jedi/issues/598 |
| 189 | try: |
| 190 | if signatures: |
| 191 | signatures[0].params |
| 192 | except AttributeError: |
| 193 | pass |
| 194 | |
| 195 | return [Signature.from_jedi_signature(sig) for sig in signatures] |
| 196 | |
| 197 | |
| 198 | def get_signatures_using_eval( |
no test coverage detected