1
0
Fork 0

Merging upstream version 3.0.22.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 18:29:22 +01:00
parent d6d0b498a1
commit ff76e41cf8
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4 changed files with 26 additions and 17 deletions

View file

@ -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

View file

@ -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
------------------

View file

@ -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

View file

@ -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,