Commit Graph

40 Commits

Author SHA1 Message Date
Victor Stinner 4c6d4f5cb3
gh-120417: Remove unused imports in the stdlib (#120420) 2024-06-12 20:56:42 +02:00
Lysandros Nikolaou 02e74c3562
gh-118908: Fix completions after namespace change in REPL (#120370) 2024-06-12 10:21:53 +02:00
Pablo Galindo Salgado 34e4d3287e
gh-120221: Deliver real singals on Ctrl-C and Ctrl-Z in the new REPL (#120354) 2024-06-11 20:20:25 +01:00
Eugene Triguba 86a8a1c57a
gh-118908: Limit exposed globals from internal imports and definitions on new REPL startup (#119547) 2024-06-11 17:40:31 +00:00
Matt Wozniski 32a0faba43
gh-119517: Fixes for pasting in pyrepl (#120253)
* Remove pyrepl's optimization for self-insert

This will be replaced by a less specialized optimization.

* Use line-buffering when pyrepl echoes pastes

Previously echoing was totally suppressed until the entire command had
been pasted and the terminal ended paste mode, but this gives the user
no feedback to indicate that an operation is in progress. Drawing
something to the screen once per line strikes a balance between
perceived responsiveness and performance.

* Remove dead code from pyrepl

`msg_at_bottom` is always true.

* Speed up pyrepl's screen rendering computation

The Reader in pyrepl doesn't hold a complete representation of the
screen area being drawn as persistent state. Instead, it recomputes it,
on each keypress. This is fast enough for a few hundred bytes, but
incredibly slow as the input buffer grows into the kilobytes (likely
because of pasting).

Rather than making some expensive and expansive changes to the repl's
internal representation of the screen, add some caching: remember some
data from one refresh to the next about what was drawn to the screen
and, if we don't find anything that has invalidated the results that
were computed last time around, reuse them. To keep this caching as
simple as possible, all we'll do is look for lines in the buffer that
were above the cursor the last time we were asked to update the screen,
and that are still above the cursor now. We assume that nothing can
affect a line that comes before both the old and new cursor location
without us being informed. Based on this assumption, we can reuse old
lines, which drastically speeds up the overwhelmingly common case where
the user is typing near the end of the buffer.

* Speed up pyrepl prompt drawing

Cache the `can_colorize()` call rather than repeatedly recomputing it.
This call looks up an environment variable, and is called once per
character typed at the REPL. The environment variable lookup shows up as
a hot spot when profiling, and we don't expect this to change while the
REPL is running.

* Speed up pasting multiple lines into the REPL

Previously, we were checking whether the command should be accepted each
time a line break was encountered, but that's not the expected behavior.
In bracketed paste mode, we expect everything pasted to be part of
a single block of code, and encountering a newline shouldn't behave like
a user pressing <Enter> to execute a command. The user should always
have a chance to review the pasted command before running it.

* Use a read buffer for input in pyrepl

Previously we were reading one byte at a time, which causes much slower
IO than necessary. Instead, read in chunks, processing previously read
data before asking for more.

* Optimize finding width of a single character

`wlen` finds the width of a multi-character string by adding up the
width of each character, and then subtracting the width of any escape
sequences. It's often called for single character strings, however,
which can't possibly contain escape sequences. Optimize for that case.

* Optimize disp_str for ASCII characters

Since every ASCII character is known to display as single width, we can
avoid not only the Unicode data lookup in `disp_str` but also the one
hidden in `str_width` for them.

* Speed up cursor movements in long pyrepl commands

When the current pyrepl command buffer contains many lines, scrolling up
becomes slow. We have optimizations in place to reuse lines above the
cursor position from one refresh to the next, but don't currently try to
reuse lines below the cursor position in the same way, so we wind up
with quadratic behavior where all lines of the buffer below the cursor
are recomputed each time the cursor moves up another line.

Optimize this by only computing one screen's worth of lines beyond the
cursor position. Any lines beyond that can't possibly be shown by the
console, and bounding this makes scrolling up have linear time
complexity instead.

---------

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-06-11 16:42:10 +00:00
Lysandros Nikolaou 69b3e8ea56
gh-119553: Fix console when pressing Ctrl-C within a multiline block (#120075) 2024-06-04 23:22:28 +02:00
Pablo Galindo Salgado d9095194dd
gh-119842: Honor PyOS_InputHook in the new REPL (GH-119843)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
2024-06-04 20:32:43 +02:00
Lysandros Nikolaou 010ea93b2b
gh-119553: Clear reader on Ctrl-C command (GH-119801) 2024-06-04 19:46:33 +02:00
Lysandros Nikolaou bf8e5e53d0
gh-120041: Refactor check for visible completion menu in completing_reader (#120055) 2024-06-04 19:26:44 +02:00
Lysandros Nikolaou 8fc7653766
gh-120041: Do not use append_to_screen when completions are visible (GH-120042) 2024-06-04 18:09:31 +02:00
Daniel Hollas 2e0aa731ae
gh-118835: pyrepl: Fix prompt length computation for custom prompts containing ANSI escape codes (#119942) 2024-06-03 18:07:06 +01:00
Łukasz Langa 2237946af0
gh-118894: Make asyncio REPL use pyrepl (GH-119433) 2024-05-31 22:26:02 +02:00
Arnon Yaari dae0375bd9
gh-111201: Improve pyrepl auto indentation (#119606)
- auto-indent when editing multi-line block
- ignore comments
2024-05-31 11:02:54 +02:00
Dino Viehland 0d07182821
gh-111201: Support pyrepl on Windows (#119559)
Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-31 09:49:03 +02:00
Sergey B Kirpichev 86d1a1aa88
gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (#119557) 2024-05-29 07:57:50 +01:00
Jelle Zijlstra a8e35e8eba
gh-119443: Turn off from __future__ import annotations in REPL (#119493) 2024-05-28 17:05:18 -07:00
Pablo Galindo Salgado e3bac04c37
gh-119548: Add a 'clear' command to the REPL (#119549) 2024-05-25 16:15:54 +00:00
Dino Viehland e3bf5381fd
gh-119434: Fix culmitive errors in wrapping as lines proceed (#119435)
Fix culmitive errors in wrapping as lines proceed
2024-05-22 15:03:32 -07:00
Lysandros Nikolaou 14b063cbf1
gh-111201: Use calc_complete_screen after bracketed paste in PyREPL (#119432) 2024-05-22 17:02:33 -04:00
Geoffrey Thomas ef172521a9
Remove almost all unpaired backticks in docstrings (#119231)
As reported in #117847 and #115366, an unpaired backtick in a docstring
tends to confuse e.g. Sphinx running on subclasses of standard library
objects, and the typographic style of using a backtick as an opening
quote is no longer in favor. Convert almost all uses of the form

    The variable `foo' should do xyz

to

    The variable 'foo' should do xyz

and also fix up miscellaneous other unpaired backticks (extraneous /
missing characters).

No functional change is intended here other than in human-readable
docstrings.
2024-05-22 12:35:18 -04:00
Aya Elsayed 5091c4400c
gh-118911: Trailing whitespace in a block shouldn't prevent the user from terminating the code block (#119355)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 07:56:35 +02:00
Pablo Galindo Salgado e6572e8f98
gh-111201: Speed up paste mode in the REPL (#119341)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 07:28:32 +02:00
Arnon Yaari cd516cd1f5
gh-111201: auto-indentation in _pyrepl (#119348)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 06:21:14 +02:00
Eugene Triguba 73ab83b27f
gh-119357: Increase test coverage for keymap in _pyrepl (#119358)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 04:36:01 +02:00
Lysandros Nikolaou c886bece3b
gh-111201: Add append to screen method to avoid recalculation (#119274)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 04:35:44 +02:00
Koudai Aono 506b1a3ff6
gh-119205: Fix autocompletion bug in new repl (#119229)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-21 23:22:21 +00:00
Pablo Galindo Salgado a3e4fec873
gh-118893: Evaluate all statements in the new REPL separately (#119318)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-21 23:16:56 +00:00
Lysandros Nikolaou 561ff1fa71
gh-111201: Remove readline dependency from the PyREPL (#119262) 2024-05-21 22:30:45 +02:00
Alastair Stanley 0398d93392
gh-119035: Add Ctrl+← and Ctrl+→ word-skipping keybindings to new repl (#119248)
add word-skipping ctrl keybindings to new repl
2024-05-21 18:17:41 +02:00
Daniel Hollas c0d81b2566
gh-118877: Fix AssertionError crash in pyrepl (#118936) 2024-05-20 20:21:56 +02:00
Thanos 05e1dce76d
gh-119185: Fix typo in `_pyrepl.pager`: `tempfilepager` should be `tempfile_pager` (#118881)
Fix typo in `_pyrepl.pager`: `tempfilepager` should be `tempfile_pager`

The name with no underscore doesn't exist.
2024-05-20 10:31:43 -04:00
Alex Waygood 0883fd22e6
Enable some stricter mypy settings on `Lib/_pyrepl` (#119077) 2024-05-20 08:52:32 -04:00
Alex Waygood 033f5c87f1
Improve `pyrepl` type-annotation coverage (#119081) 2024-05-17 06:13:24 -04:00
Pablo Galindo Salgado a94ac56628
gh-111201: Allow pasted code to contain multiple statements in the REPL (#118712)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-07 16:01:49 +00:00
Lysandros Nikolaou e5413ec783
gh-118682: Revert forcing str commands, allow class commands in pyrepl (#118709) 2024-05-07 14:31:56 +00:00
Pablo Galindo Salgado 7d90b8aadb
gh-111201: Allow bracketed paste to work (GH-118700) 2024-05-07 12:54:56 +00:00
Nikita Sobolev ad3d877a12
Remove several unused imports in `_pyrepl` (#118668) 2024-05-07 13:43:18 +01:00
denballakh 040571f258
fix typo in `_pyrepl.pager`: `plainpager` -> `plain_pager` (#118675) 2024-05-06 22:56:28 +00:00
Łukasz Langa 9bf00322ba
gh-118628: Don't display pyrepl warning on Windows (#118665) 2024-05-06 19:35:22 +00:00
Pablo Galindo Salgado f27f8c790a
gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-05-05 21:32:23 +02:00