Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2acdc51

Browse files
committed
Merge branch 'main' into eager-tasks-factory
2 parents 9522c54 + b701dce commit 2acdc51

47 files changed

Lines changed: 996 additions & 691 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/c-api/unicode.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,15 @@ APIs:
509509
arguments.
510510
511511
512+
.. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj)
513+
514+
Copy an instance of a Unicode subtype to a new true Unicode object if
515+
necessary. If *obj* is already a true Unicode object (not a subtype),
516+
return the reference with incremented refcount.
517+
518+
Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.
519+
520+
512521
.. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \
513522
const char *encoding, const char *errors)
514523
@@ -616,15 +625,6 @@ APIs:
616625
.. versionadded:: 3.3
617626
618627
619-
.. c:function:: PyObject* PyUnicode_FromObject(PyObject *obj)
620-
621-
Copy an instance of a Unicode subtype to a new true Unicode object if
622-
necessary. If *obj* is already a true Unicode object (not a subtype),
623-
return the reference with incremented refcount.
624-
625-
Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.
626-
627-
628628
Locale Encoding
629629
"""""""""""""""
630630

Doc/library/unittest.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,8 @@ Loading and running tests
22812281

22822282
The *testRunner* argument can either be a test runner class or an already
22832283
created instance of it. By default ``main`` calls :func:`sys.exit` with
2284-
an exit code indicating success or failure of the tests run.
2284+
an exit code indicating success (0) or failure (1) of the tests run.
2285+
An exit code of 5 indicates that no tests were run.
22852286

22862287
The *testLoader* argument has to be a :class:`TestLoader` instance,
22872288
and defaults to :data:`defaultTestLoader`.

Doc/whatsnew/3.12.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ Other Language Changes
237237
wrapped by a :exc:`RuntimeError`. Context information is added to the
238238
exception as a :pep:`678` note. (Contributed by Irit Katriel in :gh:`77757`.)
239239

240+
* When a ``try-except*`` construct handles the entire :exc:`ExceptionGroup`
241+
and raises one other exception, that exception is no longer wrapped in an
242+
:exc:`ExceptionGroup`. (Contributed by Irit Katriel in :gh:`103590`.)
243+
244+
240245
New Modules
241246
===========
242247

Grammar/python.gram

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,14 +881,13 @@ fstring_middle[expr_ty]:
881881
| fstring_replacement_field
882882
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
883883
fstring_replacement_field[expr_ty]:
884-
| '{' a=(yield_expr | star_expressions) debug_expr="="? conversion=[fstring_conversion] format=[fstring_full_format_spec] '}' {
885-
_PyPegen_formatted_value(p, a, debug_expr, conversion, format, EXTRA)
886-
}
884+
| '{' a=(yield_expr | star_expressions) debug_expr="="? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' {
885+
_PyPegen_formatted_value(p, a, debug_expr, conversion, format, rbrace, EXTRA) }
887886
| invalid_replacement_field
888-
fstring_conversion[expr_ty]:
887+
fstring_conversion[ResultTokenWithMetadata*]:
889888
| conv_token="!" conv=NAME { _PyPegen_check_fstring_conversion(p, conv_token, conv) }
890-
fstring_full_format_spec[expr_ty]:
891-
| ':' spec=fstring_format_spec* { spec ? _PyAST_JoinedStr((asdl_expr_seq*)spec, EXTRA) : NULL }
889+
fstring_full_format_spec[ResultTokenWithMetadata*]:
890+
| colon=':' spec=fstring_format_spec* { _PyPegen_setup_full_format_spec(p, colon, (asdl_expr_seq *) spec, EXTRA) }
892891
fstring_format_spec[expr_ty]:
893892
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
894893
| fstring_replacement_field

Include/internal/pycore_fileutils_windows.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ static inline BOOL _Py_GetFileInformationByName(
7575
return GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize);
7676
}
7777

78+
static inline BOOL _Py_GetFileInformationByName_ErrorIsTrustworthy(int error)
79+
{
80+
switch(error) {
81+
case ERROR_FILE_NOT_FOUND:
82+
case ERROR_PATH_NOT_FOUND:
83+
case ERROR_NOT_READY:
84+
case ERROR_BAD_NET_NAME:
85+
case ERROR_BAD_NETPATH:
86+
case ERROR_BAD_PATHNAME:
87+
case ERROR_INVALID_NAME:
88+
case ERROR_FILENAME_EXCED_RANGE:
89+
return TRUE;
90+
case ERROR_NOT_SUPPORTED:
91+
return FALSE;
92+
}
93+
return FALSE;
94+
}
95+
7896
#endif
7997

8098
#endif

Lib/asyncio/selector_events.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ def __init__(self, loop, sock, protocol, extra=None, server=None):
794794
self._buffer = collections.deque()
795795
self._conn_lost = 0 # Set when call to connection_lost scheduled.
796796
self._closing = False # Set when close() called.
797+
self._paused = False # Set when pause_reading() called
798+
797799
if self._server is not None:
798800
self._server._attach()
799801
loop._transports[self._sock_fd] = self
@@ -839,6 +841,25 @@ def get_protocol(self):
839841
def is_closing(self):
840842
return self._closing
841843

844+
def is_reading(self):
845+
return not self.is_closing() and not self._paused
846+
847+
def pause_reading(self):
848+
if not self.is_reading():
849+
return
850+
self._paused = True
851+
self._loop._remove_reader(self._sock_fd)
852+
if self._loop.get_debug():
853+
logger.debug("%r pauses reading", self)
854+
855+
def resume_reading(self):
856+
if self._closing or not self._paused:
857+
return
858+
self._paused = False
859+
self._add_reader(self._sock_fd, self._read_ready)
860+
if self._loop.get_debug():
861+
logger.debug("%r resumes reading", self)
862+
842863
def close(self):
843864
if self._closing:
844865
return
@@ -898,9 +919,8 @@ def get_write_buffer_size(self):
898919
return sum(map(len, self._buffer))
899920

900921
def _add_reader(self, fd, callback, *args):
901-
if self._closing:
922+
if not self.is_reading():
902923
return
903-
904924
self._loop._add_reader(fd, callback, *args)
905925

906926

@@ -915,7 +935,6 @@ def __init__(self, loop, sock, protocol, waiter=None,
915935
self._read_ready_cb = None
916936
super().__init__(loop, sock, protocol, extra, server)
917937
self._eof = False
918-
self._paused = False
919938
self._empty_waiter = None
920939
if _HAS_SENDMSG:
921940
self._write_ready = self._write_sendmsg
@@ -943,25 +962,6 @@ def set_protocol(self, protocol):
943962

944963
super().set_protocol(protocol)
945964

946-
def is_reading(self):
947-
return not self._paused and not self._closing
948-
949-
def pause_reading(self):
950-
if self._closing or self._paused:
951-
return
952-
self._paused = True
953-
self._loop._remove_reader(self._sock_fd)
954-
if self._loop.get_debug():
955-
logger.debug("%r pauses reading", self)
956-
957-
def resume_reading(self):
958-
if self._closing or not self._paused:
959-
return
960-
self._paused = False
961-
self._add_reader(self._sock_fd, self._read_ready)
962-
if self._loop.get_debug():
963-
logger.debug("%r resumes reading", self)
964-
965965
def _read_ready(self):
966966
self._read_ready_cb()
967967

Lib/asyncio/unix_events.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,21 @@ def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
485485

486486
self._loop.call_soon(self._protocol.connection_made, self)
487487
# only start reading when connection_made() has been called
488-
self._loop.call_soon(self._loop._add_reader,
488+
self._loop.call_soon(self._add_reader,
489489
self._fileno, self._read_ready)
490490
if waiter is not None:
491491
# only wake up the waiter when connection_made() has been called
492492
self._loop.call_soon(futures._set_result_unless_cancelled,
493493
waiter, None)
494494

495+
def _add_reader(self, fd, callback):
496+
if not self.is_reading():
497+
return
498+
self._loop._add_reader(fd, callback)
499+
500+
def is_reading(self):
501+
return not self._paused and not self._closing
502+
495503
def __repr__(self):
496504
info = [self.__class__.__name__]
497505
if self._pipe is None:
@@ -532,7 +540,7 @@ def _read_ready(self):
532540
self._loop.call_soon(self._call_connection_lost, None)
533541

534542
def pause_reading(self):
535-
if self._closing or self._paused:
543+
if not self.is_reading():
536544
return
537545
self._paused = True
538546
self._loop._remove_reader(self._fileno)

Lib/test/test_asyncio/test_proactor_events.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ def monkey():
447447

448448
self.assertFalse(tr.is_reading())
449449

450+
def test_pause_reading_connection_made(self):
451+
tr = self.socket_transport()
452+
self.protocol.connection_made.side_effect = lambda _: tr.pause_reading()
453+
test_utils.run_briefly(self.loop)
454+
self.assertFalse(tr.is_reading())
455+
self.loop.assert_no_reader(7)
456+
457+
tr.resume_reading()
458+
self.assertTrue(tr.is_reading())
459+
460+
tr.close()
461+
self.assertFalse(tr.is_reading())
462+
450463

451464
def pause_writing_transport(self, high):
452465
tr = self.socket_transport()

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,22 @@ def test_pause_resume_reading(self):
547547
self.assertFalse(tr.is_reading())
548548
self.loop.assert_no_reader(7)
549549

550+
def test_pause_reading_connection_made(self):
551+
tr = self.socket_transport()
552+
self.protocol.connection_made.side_effect = lambda _: tr.pause_reading()
553+
test_utils.run_briefly(self.loop)
554+
self.assertFalse(tr.is_reading())
555+
self.loop.assert_no_reader(7)
556+
557+
tr.resume_reading()
558+
self.assertTrue(tr.is_reading())
559+
self.loop.assert_reader(7, tr._read_ready)
560+
561+
tr.close()
562+
self.assertFalse(tr.is_reading())
563+
self.loop.assert_no_reader(7)
564+
565+
550566
def test_read_eof_received_error(self):
551567
transport = self.socket_transport()
552568
transport.close = mock.Mock()

Lib/test/test_except_star.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,17 @@ def test_raise_handle_all_raise_one_named(self):
618618
raise orig
619619
except* (TypeError, ValueError) as e:
620620
raise SyntaxError(3)
621-
except BaseException as e:
621+
except SyntaxError as e:
622622
exc = e
623623

624-
self.assertExceptionIsLike(
625-
exc, ExceptionGroup("", [SyntaxError(3)]))
624+
self.assertExceptionIsLike(exc, SyntaxError(3))
626625

627626
self.assertExceptionIsLike(
628-
exc.exceptions[0].__context__,
627+
exc.__context__,
629628
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
630629

631630
self.assertMetadataNotEqual(orig, exc)
632-
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
631+
self.assertMetadataEqual(orig, exc.__context__)
633632

634633
def test_raise_handle_all_raise_one_unnamed(self):
635634
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
@@ -638,18 +637,17 @@ def test_raise_handle_all_raise_one_unnamed(self):
638637
raise orig
639638
except* (TypeError, ValueError) as e:
640639
raise SyntaxError(3)
641-
except ExceptionGroup as e:
640+
except SyntaxError as e:
642641
exc = e
643642

644-
self.assertExceptionIsLike(
645-
exc, ExceptionGroup("", [SyntaxError(3)]))
643+
self.assertExceptionIsLike(exc, SyntaxError(3))
646644

647645
self.assertExceptionIsLike(
648-
exc.exceptions[0].__context__,
646+
exc.__context__,
649647
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
650648

651649
self.assertMetadataNotEqual(orig, exc)
652-
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
650+
self.assertMetadataEqual(orig, exc.__context__)
653651

654652
def test_raise_handle_all_raise_two_named(self):
655653
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
@@ -773,23 +771,22 @@ def test_raise_handle_all_raise_one_named(self):
773771
raise orig
774772
except* (TypeError, ValueError) as e:
775773
raise SyntaxError(3) from e
776-
except BaseException as e:
774+
except SyntaxError as e:
777775
exc = e
778776

779-
self.assertExceptionIsLike(
780-
exc, ExceptionGroup("", [SyntaxError(3)]))
777+
self.assertExceptionIsLike(exc, SyntaxError(3))
781778

782779
self.assertExceptionIsLike(
783-
exc.exceptions[0].__context__,
780+
exc.__context__,
784781
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
785782

786783
self.assertExceptionIsLike(
787-
exc.exceptions[0].__cause__,
784+
exc.__cause__,
788785
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
789786

790787
self.assertMetadataNotEqual(orig, exc)
791-
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
792-
self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
788+
self.assertMetadataEqual(orig, exc.__context__)
789+
self.assertMetadataEqual(orig, exc.__cause__)
793790

794791
def test_raise_handle_all_raise_one_unnamed(self):
795792
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
@@ -799,23 +796,22 @@ def test_raise_handle_all_raise_one_unnamed(self):
799796
except* (TypeError, ValueError) as e:
800797
e = sys.exception()
801798
raise SyntaxError(3) from e
802-
except ExceptionGroup as e:
799+
except SyntaxError as e:
803800
exc = e
804801

805-
self.assertExceptionIsLike(
806-
exc, ExceptionGroup("", [SyntaxError(3)]))
802+
self.assertExceptionIsLike(exc, SyntaxError(3))
807803

808804
self.assertExceptionIsLike(
809-
exc.exceptions[0].__context__,
805+
exc.__context__,
810806
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
811807

812808
self.assertExceptionIsLike(
813-
exc.exceptions[0].__cause__,
809+
exc.__cause__,
814810
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
815811

816812
self.assertMetadataNotEqual(orig, exc)
817-
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
818-
self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
813+
self.assertMetadataEqual(orig, exc.__context__)
814+
self.assertMetadataEqual(orig, exc.__cause__)
819815

820816
def test_raise_handle_all_raise_two_named(self):
821817
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])

0 commit comments

Comments
 (0)