Ethan Furman
a02cb474f9
bpo-38659: [Enum] add _simple_enum decorator (GH-25497)
...
add:
* `_simple_enum` decorator to transform a normal class into an enum
* `_test_simple_enum` function to compare
* `_old_convert_` to enable checking `_convert_` generated enums
`_simple_enum` takes a normal class and converts it into an enum:
@simple_enum(Enum)
class Color:
RED = 1
GREEN = 2
BLUE = 3
`_old_convert_` works much like` _convert_` does, using the original logic:
# in a test file
import socket, enum
CheckedAddressFamily = enum._old_convert_(
enum.IntEnum, 'AddressFamily', 'socket',
lambda C: C.isupper() and C.startswith('AF_'),
source=_socket,
)
`_test_simple_enum` takes a traditional enum and a simple enum and
compares the two:
# in the REPL or the same module as Color
class CheckedColor(Enum):
RED = 1
GREEN = 2
BLUE = 3
_test_simple_enum(CheckedColor, Color)
_test_simple_enum(CheckedAddressFamily, socket.AddressFamily)
Any important differences will raise a TypeError
2021-04-21 10:20:44 -07:00
..
2020-12-18 09:26:04 -08:00
2021-03-13 19:15:44 -08:00
2021-03-29 19:22:13 +02:00
2021-04-04 09:01:23 +09:00
2021-04-16 11:26:40 +02:00
2021-03-30 17:37:37 +09:00
2020-10-14 17:43:31 +02:00
2021-01-30 16:42:36 +00:00
2021-02-01 21:32:50 +01:00
2021-04-21 10:20:44 -07:00
2021-03-31 01:19:38 -04:00
2021-04-21 12:41:19 +01:00
2021-04-16 11:27:00 +02:00
2021-04-13 18:17:03 +09:00
2021-04-16 19:42:34 +02:00
2021-04-05 17:39:49 +01:00
2021-04-15 00:09:11 +03:00
2021-04-21 10:20:44 -07:00
2021-04-21 10:20:44 -07:00
2021-04-05 13:19:13 -04:00
2021-04-09 20:45:50 -07:00
2021-04-11 06:26:09 -07:00
2020-07-28 09:41:57 +01:00
2021-03-31 00:11:29 +03:00
2021-03-29 22:39:31 +09:00
2020-06-23 10:21:26 -04:00
2021-03-22 09:32:11 +01:00
2020-12-23 20:33:48 -08:00
2020-07-16 09:13:05 +03:00
2021-04-04 17:01:10 +09:00
2020-10-07 16:43:44 -07:00
2021-04-14 03:24:33 +02:00
2021-04-06 11:18:41 +09:00
2021-03-03 08:58:57 -08:00
2020-10-06 10:40:50 -07:00
2020-12-23 09:40:56 -08:00
2021-04-21 10:20:44 -07:00
2020-11-22 10:28:34 +02:00
2020-12-31 11:44:46 +02:00
2021-04-02 09:15:21 -07:00
2020-11-01 01:08:48 -08:00
2020-10-19 22:04:01 -07:00
2021-04-13 13:51:49 +09:00
2021-02-14 14:41:57 -08:00
2021-01-06 04:14:42 +02:00
2021-02-13 01:49:18 -05:00
2020-11-28 02:11:19 -05:00
2021-04-02 09:01:57 +09:00
2021-03-29 12:28:14 +09:00
2020-11-17 15:18:05 -08:00
2020-10-24 21:14:23 +03:00
2021-01-20 09:56:21 +01:00
2021-04-21 12:41:19 +01:00
2021-02-03 13:25:28 -08:00
2021-04-01 16:00:31 +01:00
2021-03-02 11:06:20 -06:00
2021-04-21 10:20:44 -07:00
2020-11-23 18:29:37 +02:00
2021-04-14 14:12:58 +09:00
2020-12-18 20:10:20 +01:00
2021-03-21 21:30:55 -05:00
2021-03-15 11:39:31 -07:00
2020-06-28 15:40:54 +09:00
2020-10-20 19:45:38 +03:00
2020-10-12 07:33:34 -07:00
2021-04-13 13:51:49 +09:00
2021-04-19 07:27:10 +02:00
2020-09-27 01:47:25 +01:00
2021-03-27 06:55:03 -07:00
2020-06-20 11:10:31 +03:00
2021-04-03 15:31:15 -07:00
2021-04-21 12:41:19 +01:00
2021-04-14 03:24:33 +02:00
2020-08-11 06:26:59 -07:00
2021-02-26 14:51:55 -08:00
2020-11-06 18:45:56 -08:00
2021-04-12 14:17:40 +02:00
2021-04-13 13:51:49 +09:00
2021-03-20 16:06:27 -07:00
2021-04-09 22:28:15 +01:00
2020-10-07 16:43:44 -07:00
2021-04-06 11:48:59 +01:00
2021-04-04 09:01:23 +09:00
2021-04-09 21:52:49 +01:00
2021-04-01 08:25:59 -07:00
2020-11-29 10:23:15 -08:00
2021-04-03 15:31:15 -07:00
2021-01-02 17:03:53 +01:00
2021-03-30 21:17:26 -07:00
2020-12-17 20:22:29 +01:00
2021-04-13 19:59:24 -04:00
2021-01-20 09:56:21 +01:00
2021-04-21 10:20:44 -07:00
2020-07-25 22:58:45 +03:00
2021-04-16 11:26:06 +02:00
2021-03-29 14:40:40 +02:00
2021-04-19 20:29:48 -07:00
2021-04-21 10:20:44 -07:00
2020-06-30 22:48:15 +09:00
2021-03-23 19:22:57 +01:00
2020-10-19 10:33:43 +03:00
2020-07-22 20:13:37 -07:00
2020-10-29 02:44:35 -07:00
2021-03-23 17:42:51 +01:00
2021-03-29 12:28:14 +09:00
2020-11-22 10:28:34 +02:00
2021-03-12 15:25:49 -08:00
2020-06-20 11:10:31 +03:00
2020-11-22 10:28:34 +02:00
2020-12-31 20:19:30 +00:00
2021-04-21 10:20:44 -07:00
2021-02-07 16:44:42 -08:00
2021-03-29 12:28:14 +09:00
2020-10-03 20:45:55 +01:00
2021-04-14 17:12:34 +02:00
2020-12-12 13:26:44 -08:00
2021-03-29 12:28:14 +09:00
2020-10-18 20:01:15 +03:00
2021-04-12 10:42:53 +02:00
2020-09-22 16:16:46 +03:00
2021-04-15 21:38:45 +01:00
2021-01-24 12:23:17 +03:00
2021-02-01 21:16:38 +05:30
2021-02-23 09:43:04 -08:00
2020-12-16 22:38:32 +01:00
2020-09-07 18:55:22 +03:00
2021-01-25 14:26:19 -08:00
2021-04-21 12:41:19 +01:00
2021-04-21 10:20:44 -07:00
2020-11-08 10:46:55 +01:00
2020-12-15 18:12:54 -08:00
2021-04-06 08:56:57 -07:00