8000 Merge remote-tracking branch 'upstream/main' into tvobject · python/cpython@a85fb6c · GitHub
[go: up one dir, main page]

Skip to content

Commit a85fb6c

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tvobject
2 parents b36b7af + b701dce commit a85fb6c

21 files changed

+698
-570
lines changed

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

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/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)])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not wrap a single exception raised from a ``try-except*`` construct in an :exc:`ExceptionGroup`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Isolate :mod:`!_multibytecodec` and codecs extension modules. Patches by
2+
Erlend E. Aasland.

0 commit comments

Comments
 (0)
0