MCPcopy
hub / github.com/prompt-toolkit/ptpython / get_jedi_script_from_document

Function get_jedi_script_from_document

src/ptpython/utils.py:60–89  ·  view source on GitHub ↗
(
    document: Document, locals: dict[str, Any], globals: dict[str, Any]
)

Source from the content-addressed store, hash-verified

58
59
60def 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}""")

Callers 2

get_completionsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected