Skip to content

Commit fc91a83

Browse files
authored
Merge branch 'main' into gh-148665-shutdown
2 parents 1622e12 + 1f9d20b commit fc91a83

26 files changed

Lines changed: 244 additions & 128 deletions

Doc/c-api/type.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ but need extra remarks for use as slots:
699699
700700
.. soft-deprecated:: 3.15
701701
702-
When not targetting older Python versions, pefer :c:macro:`!Py_tp_bases`.
702+
When not targeting older Python versions, prefer :c:macro:`!Py_tp_bases`.
703703
704704
The following slots do not correspond to public fields in the
705705
underlying structures:

Doc/library/ast.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ Control flow
13661366

13671367
``try`` blocks which are followed by ``except*`` clauses. The attributes are the
13681368
same as for :class:`Try` but the :class:`ExceptHandler` nodes in ``handlers``
1369-
are interpreted as ``except*`` blocks rather then ``except``.
1369+
are interpreted as ``except*`` blocks rather than ``except``.
13701370

13711371
.. doctest::
13721372

Doc/library/compression.zstd.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Advanced parameter control
503503
The :meth:`~.bounds` method can be used on any attribute to get the valid
504504
values for that parameter.
505505

506-
Parameters are optional; any omitted parameter will have it's value selected
506+
Parameters are optional; any omitted parameter will have its value selected
507507
automatically.
508508

509509
Example getting the lower and upper bound of :attr:`~.compression_level`::
@@ -732,7 +732,7 @@ Advanced parameter control
732732

733733
An :class:`~enum.IntEnum` containing the advanced decompression parameter
734734
keys that can be used when decompressing data. Parameters are optional; any
735-
omitted parameter will have it's value selected automatically.
735+
omitted parameter will have its value selected automatically.
736736

737737
The :meth:`~.bounds` method can be used on any attribute to get the valid
738738
values for that parameter.

Doc/library/functions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,11 @@ are always available. They are listed here in alphabetical order.
21792179
in the same way that keywords in a class
21802180
definition (besides *metaclass*) would.
21812181

2182+
Unlike a :keyword:`class` statement, the three argument form does not
2183+
call the metaclass ``__prepare__`` method (see :ref:`prepare`). Use
2184+
:func:`types.new_class` to dynamically create a class using the
2185+
appropriate metaclass.
2186+
21822187
See also :ref:`class-customization`.
21832188

21842189
.. versionchanged:: 3.6

Doc/library/sys.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
21352135
returned by the :func:`open` function. Their parameters are chosen as
21362136
follows:
21372137

2138-
* The encoding and error handling are is initialized from
2138+
* The encoding and error handling are initialized from
21392139
:c:member:`PyConfig.stdio_encoding` and :c:member:`PyConfig.stdio_errors`.
21402140

21412141
On Windows, UTF-8 is used for the console device. Non-character

Doc/whatsnew/3.14.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,16 @@ Changes in the Python API
33123312
This temporary change affects other threads.
33133313
(Contributed by Serhiy Storchaka in :gh:`69998`.)
33143314

3315+
* :func:`pickle.dump` and :func:`pickle.dumps` now raise
3316+
:exc:`~pickle.PicklingError` for some failures that previously raised
3317+
:exc:`AttributeError`, :exc:`ImportError`, :exc:`ValueError`,
3318+
:exc:`UnicodeEncodeError` or :exc:`!PicklingError`,
3319+
depending on the implementation
3320+
(for example, pickling a local object, or an object whose module cannot be imported).
3321+
The original exception is chained to the :exc:`!PicklingError`.
3322+
Code that caught these exceptions should also catch :exc:`!PicklingError`.
3323+
(Contributed by Serhiy Storchaka in :gh:`122311`.)
3324+
33153325
* :class:`types.UnionType` is now an alias for :class:`typing.Union`,
33163326
causing changes in some behaviors.
33173327
See :ref:`above <whatsnew314-typing-union>` for more details.

Lib/asyncio/base_subprocess.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(self, loop, protocol, args, shell,
2626
self._pending_calls = collections.deque()
2727
self._pipes = {}
2828
self._finished = False
29-
self._pipes_connected = False
3029

3130
if stdin == subprocess.PIPE:
3231
self._pipes[0] = None
@@ -214,7 +213,6 @@ async def _connect_pipes(self, waiter):
214213
else:
215214
if waiter is not None and not waiter.cancelled():
216215
waiter.set_result(None)
217-
self._pipes_connected = True
218216

219217
def _call(self, cb, *data):
220218
if self._pending_calls is not None:
@@ -235,6 +233,7 @@ def _process_exited(self, returncode):
235233
if self._loop.get_debug():
236234
logger.info('%r exited with return code %r', self, returncode)
237235
self._returncode = returncode
236+
238237
if self._proc.returncode is None:
239238
# asyncio uses a child watcher: copy the status into the Popen
240239
# object. On Python 3.6, it is required to avoid a ResourceWarning.
@@ -243,6 +242,13 @@ def _process_exited(self, returncode):
243242

244243
self._try_finish()
245244

245+
# gh-119710: Wake up futures waiting for wait() as soon as the process
246+
# exits.
247+
for waiter in self._exit_waiters:
248+
if not waiter.done():
249+
waiter.set_result(returncode)
250+
self._exit_waiters = None
251+
246252
async def _wait(self):
247253
"""Wait until the process exit and return the process return code.
248254
@@ -258,15 +264,7 @@ def _try_finish(self):
258264
assert not self._finished
259265
if self._returncode is None:
260266
return
261-
if not self._pipes_connected:
262-
# self._pipes_connected can be False if not all pipes were connected
263-
# because either the process failed to start or the self._connect_pipes task
264-
# got cancelled. In this broken state we consider all pipes disconnected and
265-
# to avoid hanging forever in self._wait as otherwise _exit_waiters
266-
# would never be woken up, we wake them up here.
267-
for waiter in self._exit_waiters:
268-
if not waiter.done():
269-
waiter.set_result(self._returncode)
267+
270268
if all(p is not None and p.disconnected
271269
for p in self._pipes.values()):
272270
self._finished = True
@@ -276,11 +274,6 @@ def _call_connection_lost(self, exc):
276274
try:
277275
self._protocol.connection_lost(exc)
278276
finally:
279-
# wake up futures waiting for wait()
280-
for waiter in self._exit_waiters:
281-
if not waiter.done():
282-
waiter.set_result(self._returncode)
283-
self._exit_waiters = None
284277
self._loop = None
285278
self._proc = None
286279
self._protocol = None

Lib/platform.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,21 +543,25 @@ def android_ver(release="", api_level=0, manufacturer="", model="", device="",
543543
is_emulator=False):
544544
if sys.platform == "android":
545545
try:
546-
from ctypes import CDLL, c_char_p, create_string_buffer
546+
from ctypes import CDLL, c_int, c_char_p, create_string_buffer
547+
from ctypes.util import wrap_dll_function
547548
except ImportError:
548549
pass
549550
else:
550551
# An NDK developer confirmed that this is an officially-supported
551552
# API (https://stackoverflow.com/a/28416743). Use `getattr` to avoid
552553
# private name mangling.
553-
system_property_get = getattr(CDLL("libc.so"), "__system_property_get")
554-
system_property_get.argtypes = (c_char_p, c_char_p)
554+
libc = CDLL("libc.so")
555+
556+
@wrap_dll_function(libc)
557+
def __system_property_get(name: c_char_p, value: c_char_p) -> c_int:
558+
pass
555559

556560
def getprop(name, default):
557561
# https://android.googlesource.com/platform/bionic/+/refs/tags/android-5.0.0_r1/libc/include/sys/system_properties.h#39
558562
PROP_VALUE_MAX = 92
559563
buffer = create_string_buffer(PROP_VALUE_MAX)
560-
length = system_property_get(name.encode("UTF-8"), buffer)
564+
length = __system_property_get(name.encode("UTF-8"), buffer)
561565
if length == 0:
562566
# This API doesn’t distinguish between an empty property and
563567
# a missing one.

Lib/test/pythoninfo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ def collect_windows(info_add):
995995
# windows.RtlAreLongPathsEnabled: RtlAreLongPathsEnabled()
996996
# windows.is_admin: IsUserAnAdmin()
997997
try:
998-
import ctypes
998+
import ctypes.util
999999
if not hasattr(ctypes, 'WinDLL'):
10001000
raise ImportError
10011001
except ImportError:
@@ -1004,20 +1004,19 @@ def collect_windows(info_add):
10041004
ntdll = ctypes.WinDLL('ntdll')
10051005
BOOLEAN = ctypes.c_ubyte
10061006
try:
1007-
RtlAreLongPathsEnabled = ntdll.RtlAreLongPathsEnabled
1007+
@ctypes.util.wrap_dll_function(ntdll)
1008+
def RtlAreLongPathsEnabled() -> BOOLEAN:
1009+
pass
10081010
except AttributeError:
10091011
res = '<function not available>'
10101012
else:
1011-
RtlAreLongPathsEnabled.restype = BOOLEAN
1012-
RtlAreLongPathsEnabled.argtypes = ()
10131013
res = bool(RtlAreLongPathsEnabled())
10141014
info_add('windows.RtlAreLongPathsEnabled', res)
10151015

1016-
shell32 = ctypes.windll.shell32
1017-
IsUserAnAdmin = shell32.IsUserAnAdmin
1018-
IsUserAnAdmin.restype = BOOLEAN
1019-
IsUserAnAdmin.argtypes = ()
1020-
info_add('windows.is_admin', IsUserAnAdmin())
1016+
@ctypes.util.wrap_dll_function(ctypes.windll.shell32)
1017+
def IsUserAnAdmin() -> BOOLEAN:
1018+
pass
1019+
info_add('windows.is_admin', bool(IsUserAnAdmin()))
10211020

10221021
try:
10231022
import _winapi

Lib/test/test_android.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ def logcat_thread():
4141

4242
try:
4343
from ctypes import CDLL, c_char_p, c_int
44-
android_log_write = getattr(CDLL("liblog.so"), "__android_log_write")
45-
android_log_write.argtypes = (c_int, c_char_p, c_char_p)
46-
ANDROID_LOG_INFO = 4
44+
from ctypes.util import wrap_dll_function
45+
liblog = CDLL("liblog.so")
46+
47+
@wrap_dll_function(liblog)
48+
def __android_log_write(prio: c_int, tag: c_char_p,
49+
text: c_char_p) -> c_int:
50+
pass
4751

4852
# Separate tests using a marker line with a different tag.
53+
ANDROID_LOG_INFO = 4
4954
tag, message = "python.test", f"{self.id()} {time()}"
50-
android_log_write(
55+
__android_log_write(
5156
ANDROID_LOG_INFO, tag.encode("UTF-8"), message.encode("UTF-8"))
5257
self.assert_log("I", tag, message, skip=True)
5358
except:

0 commit comments

Comments
 (0)