Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicField committed Jun 5, 2024
2 parents 6e07f97 + 983efcf commit 284ea3e
Show file tree
Hide file tree
Showing 38 changed files with 523 additions and 143 deletions.
7 changes: 4 additions & 3 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ operation is being performed, so the intermediate analysis object isn't useful:
Added the *show_caches* and *adaptive* parameters.

.. versionchanged:: 3.13
The *show_caches* parameter is deprecated and has no effect. The *cache_info*
field of each instruction is populated regardless of its value.

The *show_caches* parameter is deprecated and has no effect. The iterator
generates the :class:`Instruction` instances with the *cache_info*
field populated (regardless of the value of *show_caches*) and it no longer
generates separate items for the cache entries.

.. function:: findlinestarts(code)

Expand Down
4 changes: 4 additions & 0 deletions Doc/library/symtable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Examining Symbol Tables

Return ``True`` if the symbol is a parameter.

.. method:: is_type_parameter()

Return ``True`` if the symbol is a type parameter.

.. method:: is_global()

Return ``True`` if the symbol is global.
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ Functions
- range [1, 12]

* - 2
- .. attribute:: tm_day
- .. attribute:: tm_mday
- range [1, 31]

* - 3
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/zipfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ Path objects are traversable using the ``/`` operator or ``joinpath``.

.. versionadded:: 3.12

.. versionchanged:: 3.12.4
Prior to 3.12.4, ``is_symlink`` would unconditionally return ``False``.
.. versionchanged:: 3.13
Previously, ``is_symlink`` would unconditionally return ``False``.

.. method:: Path.exists()

Expand Down
24 changes: 17 additions & 7 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,8 @@ Raising ``0.0`` to a negative power results in a :exc:`ZeroDivisionError`.
Raising a negative number to a fractional power results in a :class:`complex`
number. (In earlier versions it raised a :exc:`ValueError`.)

This operation can be customized using the special :meth:`~object.__pow__` method.
This operation can be customized using the special :meth:`~object.__pow__` and
:meth:`~object.__rpow__` methods.

.. _unary:

Expand Down Expand Up @@ -1299,6 +1300,9 @@ This operation can be customized using the special :meth:`~object.__mul__` and
The ``@`` (at) operator is intended to be used for matrix multiplication. No
builtin Python types implement this operator.

This operation can be customized using the special :meth:`~object.__matmul__` and
:meth:`~object.__rmatmul__` methods.

.. versionadded:: 3.5

.. index::
Expand All @@ -1314,8 +1318,10 @@ integer; the result is that of mathematical division with the 'floor' function
applied to the result. Division by zero raises the :exc:`ZeroDivisionError`
exception.

This operation can be customized using the special :meth:`~object.__truediv__` and
:meth:`~object.__floordiv__` methods.
The division operation can be customized using the special :meth:`~object.__truediv__`
and :meth:`~object.__rtruediv__` methods.
The floor division operation can be customized using the special
:meth:`~object.__floordiv__` and :meth:`~object.__rfloordiv__` methods.

.. index::
single: modulo
Expand All @@ -1340,7 +1346,8 @@ also overloaded by string objects to perform old-style string formatting (also
known as interpolation). The syntax for string formatting is described in the
Python Library Reference, section :ref:`old-string-formatting`.

The *modulo* operation can be customized using the special :meth:`~object.__mod__` method.
The *modulo* operation can be customized using the special :meth:`~object.__mod__`
and :meth:`~object.__rmod__` methods.

The floor division operator, the modulo operator, and the :func:`divmod`
function are not defined for complex numbers. Instead, convert to a floating
Expand All @@ -1367,7 +1374,8 @@ This operation can be customized using the special :meth:`~object.__add__` and
The ``-`` (subtraction) operator yields the difference of its arguments. The
numeric arguments are first converted to a common type.

This operation can be customized using the special :meth:`~object.__sub__` method.
This operation can be customized using the special :meth:`~object.__sub__` and
:meth:`~object.__rsub__` methods.


.. _shifting:
Expand All @@ -1388,8 +1396,10 @@ The shifting operations have lower priority than the arithmetic operations:
These operators accept integers as arguments. They shift the first argument to
the left or right by the number of bits given by the second argument.

This operation can be customized using the special :meth:`~object.__lshift__` and
:meth:`~object.__rshift__` methods.
The left shift operation can be customized using the special :meth:`~object.__lshift__`
and :meth:`~object.__rlshift__` methods.
The right shift operation can be customized using the special :meth:`~object.__rshift__`
and :meth:`~object.__rrshift__` methods.

.. index:: pair: exception; ValueError

Expand Down
9 changes: 8 additions & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,13 @@ dis
the ``show_offsets`` parameter.
(Contributed by Irit Katriel in :gh:`112137`.)

* :meth:`~dis.get_instructions` no longer represents cache entries as
separate instructions. Instead, it returns them as part of the
:class:`~dis.Instruction`, in the new *cache_info* field. The
*show_caches* argument to :meth:`~dis.get_instructions` is
deprecated and no longer has any effect.
(Contributed by Irit Katriel in :gh:`112962`.)

.. _whatsnew313-doctest:

doctest
Expand Down Expand Up @@ -1006,7 +1013,7 @@ random
------

* Add a :ref:`command-line interface <random-cli>`.
(Contributed by Hugo van Kemenade in :gh:`54321`.)
(Contributed by Hugo van Kemenade in :gh:`118131`.)

re
--
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_mimalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct _mimalloc_thread_state {
mi_heap_t *current_object_heap;
mi_heap_t heaps[_Py_MIMALLOC_HEAP_COUNT];
mi_tld_t tld;
int initialized;
struct llist_node page_list;
};
#endif
Expand Down
3 changes: 3 additions & 0 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,14 @@ def do(self) -> None:
import signal

self.reader.console.finish()
self.reader.finish()
os.kill(os.getpid(), signal.SIGINT)


class ctrl_c(Command):
def do(self) -> None:
self.reader.console.finish()
self.reader.finish()
raise KeyboardInterrupt


Expand Down
23 changes: 15 additions & 8 deletions Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,20 @@ def do(self) -> None:
if p:
r.insert(p)
if last_is_completer:
if not r.cmpltn_menu_visible:
r.cmpltn_menu_visible = True
r.cmpltn_menu_visible = True
r.cmpltn_message_visible = False
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
r.console, completions, r.cmpltn_menu_end,
r.use_brackets, r.sort_in_column)
r.dirty = True
elif stem + p in completions:
r.msg = "[ complete but not unique ]"
r.dirty = True
else:
r.msg = "[ not unique ]"
r.dirty = True
elif not r.cmpltn_menu_visible:
r.cmpltn_message_visible = True
if stem + p in completions:
r.msg = "[ complete but not unique ]"
r.dirty = True
else:
r.msg = "[ not unique ]"
r.dirty = True


class self_insert(commands.self_insert):
Expand All @@ -208,6 +210,9 @@ def do(self) -> None:

commands.self_insert.do(self)

if r.cmpltn_menu_visible or r.cmpltn_message_visible:
r.calc_screen = r.calc_complete_screen

if r.cmpltn_menu_visible:
stem = r.get_stem()
if len(stem) < 1:
Expand Down Expand Up @@ -236,6 +241,7 @@ class CompletingReader(Reader):
### Instance variables
cmpltn_menu: list[str] = field(init=False)
cmpltn_menu_visible: bool = field(init=False)
cmpltn_message_visible: bool = field(init=False)
cmpltn_menu_end: int = field(init=False)
cmpltn_menu_choices: list[str] = field(init=False)

Expand Down Expand Up @@ -271,6 +277,7 @@ def finish(self) -> None:
def cmpltn_reset(self) -> None:
self.cmpltn_menu = []
self.cmpltn_menu_visible = False
self.cmpltn_message_visible = False
self.cmpltn_menu_end = 0
self.cmpltn_menu_choices = []

Expand Down
12 changes: 10 additions & 2 deletions Lib/_pyrepl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

if TYPE_CHECKING:
from typing import IO
from typing import Callable


@dataclass
Expand Down Expand Up @@ -134,8 +135,15 @@ def getpending(self) -> Event:
...

@abstractmethod
def wait(self) -> None:
"""Wait for an event."""
def wait(self, timeout: float | None) -> bool:
"""Wait for an event. The return value is True if an event is
available, False if the timeout has been reached. If timeout is
None, wait forever. The timeout is in milliseconds."""
...

@property
def input_hook(self) -> Callable[[], int] | None:
"""Returns the current input hook."""
...

@abstractmethod
Expand Down
10 changes: 9 additions & 1 deletion Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,15 @@ def handle1(self, block: bool = True) -> bool:
self.dirty = True

while True:
event = self.console.get_event(block)
input_hook = self.console.input_hook
if input_hook:
input_hook()
# We use the same timeout as in readline.c: 100ms
while not self.console.wait(100):
input_hook()
event = self.console.get_event(block=False)
else:
event = self.console.get_event(block)
if not event: # can only happen if we're not blocking
return False

Expand Down
2 changes: 1 addition & 1 deletion Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def more_lines(unicodetext: str) -> bool:
assert not more
input_n += 1
except KeyboardInterrupt:
console.write("\nKeyboardInterrupt\n")
console.write("KeyboardInterrupt\n")
console.resetbuffer()
except MemoryError:
console.write("\nMemoryError\n")
Expand Down
22 changes: 17 additions & 5 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ def __init__(self):

def register(self, fd, flag):
self.fd = fd

def poll(self): # note: a 'timeout' argument would be *milliseconds*
r, w, e = select.select([self.fd], [], [])
# note: The 'timeout' argument is received as *milliseconds*
def poll(self, timeout: float | None = None) -> list[int]:
if timeout is None:
r, w, e = select.select([self.fd], [], [])
else:
r, w, e = select.select([self.fd], [], [], timeout/1000)
return r

poll = MinimalPoll # type: ignore[assignment]
Expand Down Expand Up @@ -385,11 +388,11 @@ def get_event(self, block: bool = True) -> Event | None:
break
return self.event_queue.get()

def wait(self):
def wait(self, timeout: float | None = None) -> bool:
"""
Wait for events on the console.
"""
self.pollob.poll()
return bool(self.pollob.poll(timeout))

def set_cursor_vis(self, visible):
"""
Expand Down Expand Up @@ -527,6 +530,15 @@ def clear(self):
self.__posxy = 0, 0
self.screen = []

@property
def input_hook(self):
try:
import posix
except ImportError:
return None
if posix._is_inputhook_installed():
return posix._inputhook

def __enable_bracketed_paste(self) -> None:
os.write(self.output_fd, b"\x1b[?2004h")

Expand Down
22 changes: 20 additions & 2 deletions Lib/_pyrepl/windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from multiprocessing import Value
import os
import sys
import time
import msvcrt

from abc import ABC, abstractmethod
from collections import deque
Expand Down Expand Up @@ -202,6 +204,15 @@ def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None:
self.screen = screen
self.move_cursor(cx, cy)

@property
def input_hook(self):
try:
import nt
except ImportError:
return None
if nt._is_inputhook_installed():
return nt._inputhook

def __write_changed_line(
self, y: int, oldline: str, newline: str, px_coord: int
) -> None:
Expand Down Expand Up @@ -460,9 +471,16 @@ def getpending(self) -> Event:
processed."""
return Event("key", "", b"")

def wait(self) -> None:
def wait(self, timeout: float | None) -> bool:
"""Wait for an event."""
raise NotImplementedError("No wait support")
# Poor man's Windows select loop
start_time = time.time()
while True:
if msvcrt.kbhit(): # type: ignore[attr-defined]
return True
if timeout and time.time() - start_time > timeout:
return False
time.sleep(0.01)

def repaint(self) -> None:
raise NotImplementedError("No repaint support")
Expand Down
22 changes: 13 additions & 9 deletions Lib/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,16 @@ def add_filters(self, filterer, filters):

def _configure_queue_handler(self, klass, **kwargs):
if 'queue' in kwargs:
q = kwargs['queue']
q = kwargs.pop('queue')
else:
q = queue.Queue() # unbounded
rhl = kwargs.get('respect_handler_level', False)
if 'listener' in kwargs:
lklass = kwargs['listener']
else:
lklass = logging.handlers.QueueListener
listener = lklass(q, *kwargs.get('handlers', []), respect_handler_level=rhl)
handler = klass(q)

rhl = kwargs.pop('respect_handler_level', False)
lklass = kwargs.pop('listener', logging.handlers.QueueListener)
handlers = kwargs.pop('handlers', [])

listener = lklass(q, *handlers, respect_handler_level=rhl)
handler = klass(q, **kwargs)
handler.listener = listener
return handler

Expand Down Expand Up @@ -781,8 +781,12 @@ def configure_handler(self, config):
# raise ValueError('No handlers specified for a QueueHandler')
if 'queue' in config:
from multiprocessing.queues import Queue as MPQueue
from multiprocessing import Manager as MM
proxy_queue = MM().Queue()
proxy_joinable_queue = MM().JoinableQueue()
qspec = config['queue']
if not isinstance(qspec, (queue.Queue, MPQueue)):
if not isinstance(qspec, (queue.Queue, MPQueue,
type(proxy_queue), type(proxy_joinable_queue))):
if isinstance(qspec, str):
q = self.resolve(qspec)
if not callable(q):
Expand Down
Loading

0 comments on commit 284ea3e

Please sign in to comment.