Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-119102
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenetriguba committed May 21, 2024
2 parents cbb6f3a + e03dde5 commit 84ccfa4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,8 @@ to sockets.
Return a :term:`file object` associated with the socket. The exact returned
type depends on the arguments given to :meth:`makefile`. These arguments are
interpreted the same way as by the built-in :func:`open` function, except
the only supported *mode* values are ``'r'`` (default), ``'w'`` and ``'b'``.
the only supported *mode* values are ``'r'`` (default), ``'w'``, ``'b'``, or
a combination of those.

The socket must be in blocking mode; it can have a timeout, but the file
object's internal buffer may end up in an inconsistent state if a timeout
Expand Down
20 changes: 16 additions & 4 deletions Doc/tutorial/inputoutput.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,23 @@ printing space-separated values. There are several ways to format output.
* The :meth:`str.format` method of strings requires more manual
effort. You'll still use ``{`` and ``}`` to mark where a variable
will be substituted and can provide detailed formatting directives,
but you'll also need to provide the information to be formatted.
but you'll also need to provide the information to be formatted. In the following code
block there are two examples of how to format variables:


::

>>> yes_votes = 42_572_654
>>> no_votes = 43_132_495
>>> percentage = yes_votes / (yes_votes + no_votes)
>>> total_votes = 85_705_149
>>> percentage = yes_votes / total_votes
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
' 42572654 YES votes 49.67%'

Notice how the ``yes_votes`` are padded with spaces and a negative sign only for negative numbers.
The example also prints ``percentage`` multiplied by 100, with 2 decimal
places and followed by a percent sign (see :ref:`formatspec` for details).


* Finally, you can do all the string handling yourself by using string slicing and
concatenation operations to create any layout you can imagine. The
string type has some methods that perform useful operations for padding
Expand Down Expand Up @@ -197,7 +204,12 @@ notation. ::
Jack: 4098; Sjoerd: 4127; Dcab: 8637678

This is particularly useful in combination with the built-in function
:func:`vars`, which returns a dictionary containing all local variables.
:func:`vars`, which returns a dictionary containing all local variables::

>>> table = {k: str(v) for k, v in vars().items()}
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()])
>>> print(message.format(**table))
__name__: __main__; __doc__: None; __package__: None; __loader__: ...

As an example, the following lines produce a tidily aligned
set of columns giving integers and their squares and cubes::
Expand Down
9 changes: 6 additions & 3 deletions Lib/_pyrepl/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ def _parse_key1(key, s):
ret = key[s]
s += 1
if ctrl:
if len(ret) > 1:
raise KeySpecError("\\C- must be followed by a character")
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
if len(ret) == 1:
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
elif ret in {"left", "right"}:
ret = f"ctrl {ret}"
else:
raise KeySpecError("\\C- followed by invalid key")
if meta:
ret = ["\033", ret]
else:
Expand Down
2 changes: 2 additions & 0 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def make_default_commands() -> dict[CommandName, type[Command]]:
(r"\<up>", "up"),
(r"\<down>", "down"),
(r"\<left>", "left"),
(r"\C-\<left>", "backward-word"),
(r"\<right>", "right"),
(r"\C-\<right>", "forward-word"),
(r"\<delete>", "delete"),
(r"\<backspace>", "backspace"),
(r"\M-\<backspace>", "backward-kill-word"),
Expand Down
10 changes: 6 additions & 4 deletions Lib/rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import keyword
import re
import __main__
import warnings

__all__ = ["Completer"]

Expand Down Expand Up @@ -88,10 +89,11 @@ def complete(self, text, state):
return None

if state == 0:
if "." in text:
self.matches = self.attr_matches(text)
else:
self.matches = self.global_matches(text)
with warnings.catch_warnings(action="ignore"):
if "." in text:
self.matches = self.attr_matches(text)
else:
self.matches = self.global_matches(text)
try:
return self.matches[state]
except IndexError:
Expand Down
3 changes: 2 additions & 1 deletion Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def makefile(self, mode="r", buffering=None, *,
"""makefile(...) -> an I/O stream connected to the socket
The arguments are as for io.open() after the filename, except the only
supported mode values are 'r' (default), 'w' and 'b'.
supported mode values are 'r' (default), 'w', 'b', or a combination of
those.
"""
# XXX refactor to share code?
if not set(mode) <= {"r", "w", "b"}:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore warnings on text completion inside REPL.

0 comments on commit 84ccfa4

Please sign in to comment.