Skip to content

Commit d9afabb

Browse files
committed
Merge branch 'main' into multi_inputs
2 parents ba26b80 + 0ff1611 commit d9afabb

20 files changed

+639
-204
lines changed

Doc/library/idle.rst

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -660,29 +660,61 @@ functions to be used from IDLE's Python shell.
660660
Command line usage
661661
^^^^^^^^^^^^^^^^^^
662662

663-
.. code-block:: none
663+
.. program:: idle
664664

665-
idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
665+
IDLE can be invoked from the command line with various options. The general syntax is:
666666

667-
-c command run command in the shell window
668-
-d enable debugger and open shell window
669-
-e open editor window
670-
-h print help message with legal combinations and exit
671-
-i open shell window
672-
-r file run file in shell window
673-
-s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
674-
-t title set title of shell window
675-
- run stdin in shell (- must be last option before args)
667+
.. code-block:: bash
676668
677-
If there are arguments:
669+
python -m idlelib [options] [file ...]
678670
679-
* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
680-
``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
681-
or ``'-r'``. No editor window is opened, even if that is the default
682-
set in the Options dialog.
671+
The following options are available:
672+
673+
.. option:: -c <command>
674+
675+
Run the specified Python command in the shell window.
676+
For example, pass ``-c "print('Hello, World!')"``.
677+
On Windows, the outer quotes must be double quotes as shown.
678+
679+
.. option:: -d
680+
681+
Enable the debugger and open the shell window.
682+
683+
.. option:: -e
684+
685+
Open an editor window.
686+
687+
.. option:: -h
688+
689+
Print a help message with legal combinations of options and exit.
690+
691+
.. option:: -i
692+
693+
Open a shell window.
694+
695+
.. option:: -r <file>
696+
697+
Run the specified file in the shell window.
698+
699+
.. option:: -s
700+
701+
Run the startup file (as defined by the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`) before opening the shell window.
702+
703+
.. option:: -t <title>
704+
705+
Set the title of the shell window.
706+
707+
.. option:: -
708+
709+
Read and execute standard input in the shell window. This option must be the last one before any arguments.
710+
711+
If arguments are provided:
712+
713+
- If ``-``, ``-c``, or ``-r`` is used, all arguments are placed in ``sys.argv[1:]``,
714+
and ``sys.argv[0]`` is set to ``''``, ``'-c'``, or ``'-r'`` respectively.
715+
No editor window is opened, even if that is the default set in the *Options* dialog.
716+
- Otherwise, arguments are treated as files to be opened for editing, and ``sys.argv`` reflects the arguments passed to IDLE itself.
683717

684-
* Otherwise, arguments are files opened for editing and
685-
``sys.argv`` reflects the arguments passed to IDLE itself.
686718

687719
Startup failure
688720
^^^^^^^^^^^^^^^

Doc/library/multiprocessing.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,35 +380,40 @@ However, if you really do need to use some shared data then
380380
proxies.
381381

382382
A manager returned by :func:`Manager` will support types
383-
:class:`list`, :class:`dict`, :class:`~managers.Namespace`, :class:`Lock`,
383+
:class:`list`, :class:`dict`, :class:`set`, :class:`~managers.Namespace`, :class:`Lock`,
384384
:class:`RLock`, :class:`Semaphore`, :class:`BoundedSemaphore`,
385385
:class:`Condition`, :class:`Event`, :class:`Barrier`,
386386
:class:`Queue`, :class:`Value` and :class:`Array`. For example, ::
387387

388388
from multiprocessing import Process, Manager
389389

390-
def f(d, l):
390+
def f(d, l, s):
391391
d[1] = '1'
392392
d['2'] = 2
393393
d[0.25] = None
394394
l.reverse()
395+
s.add('a')
396+
s.add('b')
395397

396398
if __name__ == '__main__':
397399
with Manager() as manager:
398400
d = manager.dict()
399401
l = manager.list(range(10))
402+
s = manager.set()
400403

401-
p = Process(target=f, args=(d, l))
404+
p = Process(target=f, args=(d, l, s))
402405
p.start()
403406
p.join()
404407

405408
print(d)
406409
print(l)
410+
print(s)
407411

408412
will print ::
409413

410414
{0.25: None, 1: '1', '2': 2}
411415
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
416+
{'a', 'b'}
412417

413418
Server process managers are more flexible than using shared memory objects
414419
because they can be made to support arbitrary object types. Also, a single
@@ -1942,6 +1947,15 @@ their parent process exits. The manager classes are defined in the
19421947

19431948
Create a shared :class:`list` object and return a proxy for it.
19441949

1950+
.. method:: set()
1951+
set(sequence)
1952+
set(mapping)
1953+
1954+
Create a shared :class:`set` object and return a proxy for it.
1955+
1956+
.. versionadded:: next
1957+
:class:`set` support was added.
1958+
19451959
.. versionchanged:: 3.6
19461960
Shared objects are capable of being nested. For example, a shared
19471961
container object such as a shared list can contain other shared objects

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,11 @@ multiprocessing
700700

701701
(Contributed by Roy Hyunjin Han for :gh:`103134`.)
702702

703+
* Add support for shared :class:`set` objects via
704+
:meth:`SyncManager.set() <multiprocessing.managers.SyncManager.set>`.
705+
The :func:`set` in :func:`multiprocessing.Manager` method is now available.
706+
(Contributed by Mingyu Park in :gh:`129949`.)
707+
703708

704709
operator
705710
--------

Lib/_pydatetime.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
__all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo",
44
"MINYEAR", "MAXYEAR", "UTC")
55

6+
__name__ = "datetime"
7+
68

79
import time as _time
810
import math as _math
@@ -14,10 +16,10 @@ def _cmp(x, y):
1416

1517
def _get_class_module(self):
1618
module_name = self.__class__.__module__
17-
if module_name == '_pydatetime':
18-
return 'datetime'
19+
if module_name == 'datetime':
20+
return 'datetime.'
1921
else:
20-
return module_name
22+
return ''
2123

2224
MINYEAR = 1
2325
MAXYEAR = 9999
@@ -767,9 +769,9 @@ def __repr__(self):
767769
args.append("microseconds=%d" % self._microseconds)
768770
if not args:
769771
args.append('0')
770-
return "%s.%s(%s)" % (_get_class_module(self),
771-
self.__class__.__qualname__,
772-
', '.join(args))
772+
return "%s%s(%s)" % (_get_class_module(self),
773+
self.__class__.__qualname__,
774+
', '.join(args))
773775

774776
def __str__(self):
775777
mm, ss = divmod(self._seconds, 60)
@@ -1082,11 +1084,11 @@ def __repr__(self):
10821084
>>> repr(d)
10831085
'datetime.date(2010, 1, 1)'
10841086
"""
1085-
return "%s.%s(%d, %d, %d)" % (_get_class_module(self),
1086-
self.__class__.__qualname__,
1087-
self._year,
1088-
self._month,
1089-
self._day)
1087+
return "%s%s(%d, %d, %d)" % (_get_class_module(self),
1088+
self.__class__.__qualname__,
1089+
self._year,
1090+
self._month,
1091+
self._day)
10901092
# XXX These shouldn't depend on time.localtime(), because that
10911093
# clips the usable dates to [1970 .. 2038). At least ctime() is
10921094
# easily done without using strftime() -- that's better too because
@@ -1586,7 +1588,7 @@ def __repr__(self):
15861588
s = ", %d" % self._second
15871589
else:
15881590
s = ""
1589-
s= "%s.%s(%d, %d%s)" % (_get_class_module(self),
1591+
s = "%s%s(%d, %d%s)" % (_get_class_module(self),
15901592
self.__class__.__qualname__,
15911593
self._hour, self._minute, s)
15921594
if self._tzinfo is not None:
@@ -2162,9 +2164,9 @@ def __repr__(self):
21622164
del L[-1]
21632165
if L[-1] == 0:
21642166
del L[-1]
2165-
s = "%s.%s(%s)" % (_get_class_module(self),
2166-
self.__class__.__qualname__,
2167-
", ".join(map(str, L)))
2167+
s = "%s%s(%s)" % (_get_class_module(self),
2168+
self.__class__.__qualname__,
2169+
", ".join(map(str, L)))
21682170
if self._tzinfo is not None:
21692171
assert s[-1:] == ")"
21702172
s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
@@ -2461,12 +2463,12 @@ def __repr__(self):
24612463
if self is self.utc:
24622464
return 'datetime.timezone.utc'
24632465
if self._name is None:
2464-
return "%s.%s(%r)" % (_get_class_module(self),
2465-
self.__class__.__qualname__,
2466-
self._offset)
2467-
return "%s.%s(%r, %r)" % (_get_class_module(self),
2468-
self.__class__.__qualname__,
2469-
self._offset, self._name)
2466+
return "%s%s(%r)" % (_get_class_module(self),
2467+
self.__class__.__qualname__,
2468+
self._offset)
2469+
return "%s%s(%r, %r)" % (_get_class_module(self),
2470+
self.__class__.__qualname__,
2471+
self._offset, self._name)
24702472

24712473
def __str__(self):
24722474
return self.tzname(None)

Lib/_pyrepl/base_eventqueue.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2000-2008 Michael Hudson-Doyle <[email protected]>
2+
# Armin Rigo
3+
#
4+
# All Rights Reserved
5+
#
6+
#
7+
# Permission to use, copy, modify, and distribute this software and
8+
# its documentation for any purpose is hereby granted without fee,
9+
# provided that the above copyright notice appear in all copies and
10+
# that both that copyright notice and this permission notice appear in
11+
# supporting documentation.
12+
#
13+
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
14+
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15+
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
16+
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
17+
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
18+
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20+
21+
"""
22+
OS-independent base for an event and VT sequence scanner
23+
24+
See unix_eventqueue and windows_eventqueue for subclasses.
25+
"""
26+
27+
from collections import deque
28+
29+
from . import keymap
30+
from .console import Event
31+
from .trace import trace
32+
33+
class BaseEventQueue:
34+
def __init__(self, encoding: str, keymap_dict: dict[bytes, str]) -> None:
35+
self.compiled_keymap = keymap.compile_keymap(keymap_dict)
36+
self.keymap = self.compiled_keymap
37+
trace("keymap {k!r}", k=self.keymap)
38+
self.encoding = encoding
39+
self.events: deque[Event] = deque()
40+
self.buf = bytearray()
41+
42+
def get(self) -> Event | None:
43+
"""
44+
Retrieves the next event from the queue.
45+
"""
46+
if self.events:
47+
return self.events.popleft()
48+
else:
49+
return None
50+
51+
def empty(self) -> bool:
52+
"""
53+
Checks if the queue is empty.
54+
"""
55+
return not self.events
56+
57+
def flush_buf(self) -> bytearray:
58+
"""
59+
Flushes the buffer and returns its contents.
60+
"""
61+
old = self.buf
62+
self.buf = bytearray()
63+
return old
64+
65+
def insert(self, event: Event) -> None:
66+
"""
67+
Inserts an event into the queue.
68+
"""
69+
trace('added event {event}', event=event)
70+
self.events.append(event)
71+
72+
def push(self, char: int | bytes) -> None:
73+
"""
74+
Processes a character by updating the buffer and handling special key mappings.
75+
"""
76+
ord_char = char if isinstance(char, int) else ord(char)
77+
char = bytes(bytearray((ord_char,)))
78+
self.buf.append(ord_char)
79+
if char in self.keymap:
80+
if self.keymap is self.compiled_keymap:
81+
# sanity check, buffer is empty when a special key comes
82+
assert len(self.buf) == 1
83+
k = self.keymap[char]
84+
trace('found map {k!r}', k=k)
85+
if isinstance(k, dict):
86+
self.keymap = k
87+
else:
88+
self.insert(Event('key', k, self.flush_buf()))
89+
self.keymap = self.compiled_keymap
90+
91+
elif self.buf and self.buf[0] == 27: # escape
92+
# escape sequence not recognized by our keymap: propagate it
93+
# outside so that i can be recognized as an M-... key (see also
94+
# the docstring in keymap.py
95+
trace('unrecognized escape sequence, propagating...')
96+
self.keymap = self.compiled_keymap
97+
self.insert(Event('key', '\033', bytearray(b'\033')))
98+
for _c in self.flush_buf()[1:]:
99+
self.push(_c)
100+
101+
else:
102+
try:
103+
decoded = bytes(self.buf).decode(self.encoding)
104+
except UnicodeError:
105+
return
106+
else:
107+
self.insert(Event('key', decoded, self.flush_buf()))
108+
self.keymap = self.compiled_keymap

0 commit comments

Comments
 (0)