Commit 8c3793a
gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704)
When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. .
member = object.__new__(cls)
member = int.__new__(cls, value)
member = str.__new__(cls, value)
Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected.
(cherry picked from commit d48760b)
Co-authored-by: Ethan Furman <[email protected]>
1 parent a92c60c commit 8c3793a
File tree
4 files changed
+260
-56
lines changed- Doc/howto
- Lib
- test
- Misc/NEWS.d/next/Library
4 files changed
+260
-56
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
| 429 | + | |
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
433 | 440 | | |
434 | 441 | | |
435 | 442 | | |
| |||
895 | 902 | | |
896 | 903 | | |
897 | 904 | | |
| 905 | + | |
| 906 | + | |
898 | 907 | | |
899 | 908 | | |
900 | 909 | | |
| |||
927 | 936 | | |
928 | 937 | | |
929 | 938 | | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
930 | 944 | | |
931 | 945 | | |
932 | 946 | | |
| |||
1353 | 1367 | | |
1354 | 1368 | | |
1355 | 1369 | | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
1356 | 1377 | | |
1357 | 1378 | | |
1358 | 1379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
865 | 865 | | |
866 | 866 | | |
867 | 867 | | |
| 868 | + | |
| 869 | + | |
868 | 870 | | |
869 | 871 | | |
870 | 872 | | |
| |||
1121 | 1123 | | |
1122 | 1124 | | |
1123 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
1124 | 1131 | | |
1125 | 1132 | | |
1126 | 1133 | | |
| |||
0 commit comments