(
document: Document, locals: dict[str, Any], globals: dict[str, Any]
)
| 58 | |
| 59 | |
| 60 | def get_jedi_script_from_document( |
| 61 | document: Document, locals: dict[str, Any], globals: dict[str, Any] |
| 62 | ) -> Interpreter: |
| 63 | import jedi # We keep this import in-line, to improve start-up time. |
| 64 | |
| 65 | # Importing Jedi is 'slow'. |
| 66 | |
| 67 | try: |
| 68 | return jedi.Interpreter( |
| 69 | document.text, |
| 70 | path="input-text", |
| 71 | namespaces=[locals, globals], |
| 72 | ) |
| 73 | except ValueError: |
| 74 | # Invalid cursor position. |
| 75 | # ValueError('`column` parameter is not in a valid range.') |
| 76 | return None |
| 77 | except AttributeError: |
| 78 | # Workaround for #65: https://github.com/jonathanslenders/python-prompt-toolkit/issues/65 |
| 79 | # See also: https://github.com/davidhalter/jedi/issues/508 |
| 80 | return None |
| 81 | except IndexError: |
| 82 | # Workaround Jedi issue #514: for https://github.com/davidhalter/jedi/issues/514 |
| 83 | return None |
| 84 | except KeyError: |
| 85 | # Workaround for a crash when the input is "u'", the start of a unicode string. |
| 86 | return None |
| 87 | except Exception: |
| 88 | # Workaround for: https://github.com/jonathanslenders/ptpython/issues/91 |
| 89 | return None |
| 90 | |
| 91 | |
| 92 | _multiline_string_delims = re.compile("""[']{3}|["]{3}""") |
no outgoing calls
no test coverage detected