diff options
-rw-r--r-- | .github/workflows/test.yaml | 4 | ||||
-rw-r--r-- | CHANGELOG | 7 | ||||
-rw-r--r-- | ptpython/completer.py | 30 | ||||
-rw-r--r-- | setup.py | 2 |
4 files changed, 26 insertions, 17 deletions
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ef806cf..7ec8662 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] + python-version: [3.7, 3.8, 3.9, "3.10"] steps: - uses: actions/checkout@v2 @@ -23,14 +23,12 @@ jobs: sudo apt remove python3-pip python -m pip install --upgrade pip python -m pip install . black isort mypy pytest readme_renderer - python -m pip install . types-dataclasses # Needed for Python 3.6 pip list - name: Type Checker run: | mypy ptpython isort -c --profile black ptpython examples setup.py black --check ptpython examples setup.py - if: matrix.python-version != '3.6' - name: Run Tests run: | ./tests/run_tests.py @@ -1,6 +1,13 @@ CHANGELOG ========= +3.0.22: 2022-12-06 +------------------ + +New features: +- Improve rendering performance when there are many completions. + + 3.0.21: 2022-11-25 ------------------ diff --git a/ptpython/completer.py b/ptpython/completer.py index 2b6795d..9252106 100644 --- a/ptpython/completer.py +++ b/ptpython/completer.py @@ -476,14 +476,22 @@ class DictionaryCompleter(Completer): Complete dictionary keys. """ - def abbr_meta(text: str) -> str: + def meta_repr(value: object) -> Callable[[], str]: "Abbreviate meta text, make sure it fits on one line." - # Take first line, if multiple lines. - if len(text) > 20: - text = text[:20] + "..." - if "\n" in text: - text = text.split("\n", 1)[0] + "..." - return text + # We return a function, so that it gets computed when it's needed. + # When there are many completions, that improves the performance + # quite a bit (for the multi-column completion menu, we only need + # to display one meta text). + def get_value_repr() -> str: + text = self._do_repr(value) + + # Take first line, if multiple lines. + if "\n" in text: + text = text.split("\n", 1)[0] + "..." + + return text + + return get_value_repr match = self.item_lookup_pattern.search(document.text_before_cursor) if match is not None: @@ -512,12 +520,8 @@ class DictionaryCompleter(Completer): k_repr + "]", -len(key), display=f"[{k_repr}]", - display_meta=abbr_meta(self._do_repr(v)), + display_meta=meta_repr(v), ) - except KeyError: - # `result[k]` lookup failed. Trying to complete - # broken object. - pass except ReprFailedError: pass @@ -532,7 +536,7 @@ class DictionaryCompleter(Completer): k_repr + "]", -len(key), display=f"[{k_repr}]", - display_meta=abbr_meta(self._do_repr(result[k])), + display_meta=meta_repr(result[k]), ) except KeyError: # `result[k]` lookup failed. Trying to complete @@ -11,7 +11,7 @@ with open(os.path.join(os.path.dirname(__file__), "README.rst")) as f: setup( name="ptpython", author="Jonathan Slenders", - version="3.0.21", + version="3.0.22", url="https://github.com/prompt-toolkit/ptpython", description="Python REPL build on top of prompt_toolkit", long_description=long_description, |