Commit fc7e64d4 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

fix issue #2791: use autocomplete_property for SCAN_SAVING properties, and...

fix issue #2791: use autocomplete_property for SCAN_SAVING properties, and ensure jedi is properly patched
parent fad723be
Pipeline #48033 passed with stages
in 98 minutes and 58 seconds
......@@ -94,7 +94,7 @@ def with_eval_dict(method):
return eval_func
class property_with_eval_dict(property):
class property_with_eval_dict(autocomplete_property):
"""Combine the `with_eval_dict` and `property` decorators
"""
......
......@@ -9,83 +9,50 @@
Patch to modify the behavior of the ptpython PythonCompleter
The code for def signature_toolbar corresponds to ptpython version 2.0.4
"""
from ptpython.utils import get_jedi_script_from_document
from prompt_toolkit.completion import Completion
from jedi.inference.compiled.access import (
DirectObjectAccess,
getattr_static,
ALLOWED_DESCRIPTOR_ACCESS,
)
import ptpython.completer
import jedi
from bliss.common.utils import autocomplete_property
old_get_completions = ptpython.completer.PythonCompleter.get_completions
def NEWget_completions(self, document, complete_event):
"""
Get Python completions. Hide those starting with "_" (unless user first types the underscore).
"""
# Do Path completions
if complete_event.completion_requested or self._complete_path_while_typing(
document
):
for c in self._path_completer.get_completions(document, complete_event):
yield c
allow_underscore = document.text.endswith("_") or document.text.rpartition(".")[
-1
].startswith("_")
if allow_underscore:
yield from old_get_completions(self, document, complete_event)
else:
yield from (
c
for c in old_get_completions(self, document, complete_event)
if not c.text.startswith("_")
)
# If we are inside a string, Don't do Jedi completion.
if self._path_completer_grammar.match(document.text_before_cursor):
return
# Do Jedi Python completions.
if complete_event.completion_requested or self._complete_python_while_typing(
document
):
script = get_jedi_script_from_document(
document, self.get_locals(), self.get_globals()
)
ptpython.completer.PythonCompleter.get_completions = NEWget_completions
if script:
try:
completions = script.completions()
except TypeError:
# Issue #9: bad syntax causes completions() to fail in jedi.
# https://github.com/jonathanslenders/python-prompt-toolkit/issues/9
pass
except UnicodeDecodeError:
# Issue #43: UnicodeDecodeError on OpenBSD
# https://github.com/jonathanslenders/python-prompt-toolkit/issues/43
pass
except AttributeError:
# Jedi issue #513: https://github.com/davidhalter/jedi/issues/513
pass
except ValueError:
# Jedi issue: "ValueError: invalid \x escape"
pass
except KeyError:
# Jedi issue: "KeyError: u'a_lambda'."
# https://github.com/jonathanslenders/ptpython/issues/89
pass
except IOError:
# Jedi issue: "IOError: No such file or directory."
# https://github.com/jonathanslenders/ptpython/issues/71
pass
except AssertionError:
# In jedi.parser.__init__.py: 227, in remove_last_newline,
# the assertion "newline.value.endswith('\n')" can fail.
pass
except SystemError:
# In jedi.api.helpers.py: 144, in get_stack_at_position
# raise SystemError("This really shouldn't happen. There's a bug in Jedi.")
pass
except NotImplementedError:
# See: https://github.com/jonathanslenders/ptpython/issues/223
pass
except Exception:
# Supress all other Jedi exceptions.
pass
else:
for c in completions:
if c.name.startswith("_") and c.name == c.complete:
continue
yield Completion(
c.name_with_symbols,
len(c.complete) - len(c.name_with_symbols),
display=c.name_with_symbols,
)
old_is_allowed_getattr = DirectObjectAccess.is_allowed_getattr
import ptpython.completer
def NEWis_allowed_getattr(self, name, unsafe=False):
is_get_descriptor, not_allowed = old_is_allowed_getattr(self, name, unsafe)
if is_get_descriptor and not_allowed:
attr, _ = getattr_static(self._obj, name)
if autocomplete_property in type(attr).__bases__:
not_allowed = False
return is_get_descriptor, not_allowed
ptpython.completer.PythonCompleter.get_completions = NEWget_completions
DirectObjectAccess.is_allowed_getattr = NEWis_allowed_getattr
jedi.Interpreter._allow_descriptor_getattr_default = False
jedi.inference.compiled.access.ALLOWED_DESCRIPTOR_ACCESS += (autocomplete_property,)
......@@ -204,15 +204,9 @@ __all__ = ("BlissRepl", "embed", "cli", "configure_repl")
# patch ptpython signaturetoolbar
import bliss.shell.cli.ptpython_signature_patch
# patch ptpython completer
# patch ptpython completer, and jedi
import bliss.shell.cli.ptpython_completer_patch
# add autocomplete_property to jedi's ALLOWED_DESCRIPTOR_ACCESS
from bliss.common.utils import autocomplete_property
import jedi
jedi.Interpreter._allow_descriptor_getattr_default = False
jedi.inference.compiled.access.ALLOWED_DESCRIPTOR_ACCESS += (autocomplete_property,)
#############
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment