Spaces:
Sleeping
Sleeping
File size: 10,108 Bytes
ffaa9fc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
3.1.13
======
- remove Python 2.6 code
- add Python 3.12 enhancements
- split source code into separate files
- Enum and Flag inherit from stdlib versions
3.1.12
======
support inheriting from empty NamedTuples
3.1.10
======
prevent test_v3.py from being run as main
3.1.9
=====
Move Py2/3 specific code to dedicated files
3.1.8
=====
recalculate bits used after all flags created (sometimes needed when a custom
`__new__` is in place.
3.1.7
=====
update flag creation to (possibly) add bitwise operator methods to newly
created flags
update extend_enum() to work with 3.11 flags
3.1.6
=====
Update `dir()` on mixed enums to include mixed data type methods and
attributes.
Rename `enum_property` to `property` to match stdlib. Recommended usage is
`aenum.property` (prefix with module name).
Remove quadritic creation behavior.
BREAKING CHANGE BUG FIX that won't affect most people
Enums with a custom `__new__` that:
- use the enum machinery to generate the values; AND
- have keyword arguments set to a default (like `None`)
will fail to generate a missing value. To fix: remove the default value and
instead specify it on the member creation line.
BREAKING CHANGE
In Python 3.11 the `str()` of mixed enums will now match its `format()` which
will be the normal `str()` of the data type -- so for an IntEnum you'll see
`5` instead of `Perm.R|X`. This affects IntEnum, StrEnum, and IntFlag.
3.1.5
=====
fix support of `auto()` kwds
3.1.3
=====
rename `aenum.property` to `aenum.enum_property`
fix `enum_property` to work with `_init_` attributes
3.1.2
=====
fix `extend_enum()` for unhashable values
3.1.1
=====
fix `extend_enum()` for most cases
3.1.0
=====
AddValue is similar to the old AutoNumber: it will always activate, but
uses _generate_next_value_ to get the next value (so the user has some
control over the return data type instead of always getting an int).
BREAKING CHANGES
AutoValue is gone. It was superflous and its removal simplified the code.
Simply put the fields needed in an `_init_` and `_generate_next_value_`
will be called to supply the missing values (this is probably already what
is happening).
3.0.0
=====
standard Enum usage is unchanged
BREAKING CHANGES
Enum
- the more esoteric method of creating Enums have been modified or removed
- AutoNumber setting is gone, inherit from AutoNumberEnum instead
- creating members without specifying anything is removed (if you don't
know what this means, you weren't doing it)
Flag
- unique flags are canonical (i.e. flags with powers of two values such as
1, 2, 4, 8, 16, etc.)
- non-unique flags are aliases (i.e. values such as 3 or 7)
- iteration of Flag and flag members only uses canonical flags
ENHANCEMENTS
Member creation has been redone to match Python 3.10's methods. This also
allows all supported Pythons (2.7, 3.3+) to use the __set_name__ and
__init_subclass__ protocols (more robustly than in aenum 2.2.5)
CHANGES
enum_property() has been renamed to property() (old name still available, but
deprecated).
bin() replacement shows negative integers in twos-complement
2.2.5
=====
call __init_subclass__ after members have been added, and in Pythons < 3.6
call __set_name__ in Pythons < 3.6
do not convert/disallow private names
add iteration/len support to NamedConstant
2.2.4
=====
add support to Constant to retrieve members by value
--> class K(Constant):
... one = 1
... two = 2
--> K.one
<K.one: 1>
--> K(1)
<K.one: 1>
add pickle/deepcopy support to Constant
add support for Constant to use other Constant values
(resulting members /are not/ the same)
--> class C(Constant)
... one = K.one
... three = 3
--> C.one == K.one
True
--> C.one is K.one
False
AutoNumber and auto() now work together
Enum members are now added to the class as enum_property, which supports
unshadowing of parent class attributes when called on an Enum member:
--> class StrEnum(str, Enum):
... lower = 'lower'
... upper = 'upper'
... mixed = 'mixed'
--> StrEnum.lower
<StrEnum.lower: 'lower'>
--> StrEnum.lower.upper()
'LOWER'
--> StrEnum.upper
<StrEnum.upper: 'upper'>
--> StrEnum.upper.upper()
'UPPER'
2.2.3
=====
use members' type's methods __str__, __repr__, __format__, and
__reduce_ex__ if directly assigned in Enum class body; i.e.:
--> class Color(str, Enum):
... red = 'red'
... green = 'green'
... blue = 'blue'
... __str__ = str.__str__
--> print(repr(Color.green))
<Color.green: 'green'>
--> print(Color.green)
green
2.2.2
=====
replace _RouteClassAttributeToGetattr with enum_property (it is still
available as an alias)
support constant() and auto() being used together:
--> class Fruit(Flag):
... _order_ = 'apple banana lemon orange'
... apple = auto()
... banana = auto()
... lemon = auto()
... orange = auto()
... CitrusTypes = constant(lemon | orange)
--> list(Fruit)
[Fruit.apple, Fruit.banana, Fruit.lemon, Fruit.orange]
--> list(Fruit.CitrusTypes)
[Fruit.orange, Fruit.lemon]
--> Fruit.orange in Fruit.CitrusTypes
True
2.2.1
=====
allow Enums to be called without a value
class Color(Enum):
black = 0
red = 1
green = 2
blue = 3
#
@classmethod
def _missing_value_(cls, value):
if value is no_arg:
return cls.black
>>> Color()
<Color.black: 0>
allow Enum name use while constructing Enum (Python 3.4+ only)
--> class Color(Enum):
... _order_ = 'BLACK WHITE'
... BLACK = Color('black', '#000')
... WHITE = Color('white', '#fff')
... #
... def __init__(self, label, hex):
... self.label = label
... self.hex = hex
2.2.0
=====
BREAKING CHANGE
---------------
In Python 3+ classes defined inside an Enum no longer become members by
default; in Python 2 they still become members, but see below.
For cross-compatibility and full control two decorators are provided:
- @member --> forces item to become a member
- @nonmember --> excludes item from becoming a member
So to have an Enum that behaves the same in Python 2 and 3, use the
decorators (and other compatibility shims):
class Color(Enum):
_order_ = 'red green blue'
red = 1
green = 2
blue = 3
@nonmember
class Shades(Enum):
_order_ = 'light medium dark'
light = 1
medium = 2
dark = 3
2.1.4
=====
EnumMeta:
- change __member_new__ to __new_member__ (as the stdlib enum does)
- assign member name to enum() instances (an Enum helper for defining members)
- handle empty iterables when using functional API
- make auto() work with previous enum members
- keep searching mixins until base class is found
Enum:
- fix bug in Flag checks (ensure it is a Flag before checking the name)
- add multiple mixin support
- do not allow blank names (functional API)
- raise TypeError if _missing_* returns wrong type
- fix __format__ to honor custom __str__
extend_enum:
- support stdlib Enums
- use _generate_next_value_ if value not provided
general:
- standardize exception formatting
- use getfullargspec() in Python 3 (avoids deprecation warnings)
2.1.2
=====
when order is callable, save it for subclass use
2.1.1
=====
correctly raise TypeError for non-Enum containment checks
support combining names with | for Flag key access
support _order_ being a callable
2.1.0
=====
support Flags being combined with other data types:
- add _create_pseudo_member_values_
- add default __new__ and temporary _init_
2.0.10
======
ensure _ignore_ is set when _settings_ specified in body which includes
AutoValue
make Flag members iterable
2.0.9
=====
fix missing comma in __all__
fix extend_enum with custom __new__ methods
fix MultiValue with AutoNumber without _init_
2.0.8
=====
extend_enum now handles aliases and multivalues correctly
2.0.7
=====
support mixin types with extend_enum
init and AutoNumber can now work together
add test for new Enum using EnumMeta
add tests for variations of multivalue and init
prevent deletion of NamedConstant.constant
2.0.6
=====
constants cannot be deleted (they already couldn't be changed)
constants can be used to define other constants
2.0.5
=====
_init_ and MultiValue can now work together
2.0.4
=====
_init_ and AutoValue (and _generate_next_value_) can now work together to
supply missing values even when some of the required values per member are
absent
2.0.3
=====
add _missing_value_ and _missing_name_ methods, deprecate _missing_
make enum instances comparable
2.0.2
=====
both EnumMeta.__getattr__ and Enum.__new__ fall back to _missing_
2.0.1
=====
auto() now works with other data types
AutoNumber supports legacy Enums (fixed regression)
2.0.0
=====
Flag and IntFlag added.
1.4.7
=====
fix %-interpolation bug
defined SqlLiteEnum only if sqlite exists
support pyflakes
1.4.6
=====
version numbering error
1.4.5
=====
revert AutoNumberEnum to custom __new__ instead of AutoNumber
use _ignore_ to shield against AutoNumber magic
inherit start and init settings from base Enums
1.4.4
=====
enabled export as a decorator
enabled _order_ to replace __order__
enabled python2 support for settings, init, and start
1.4.3
=====
support _ignore_ for dynamically creating class bodies
1.4.2
=====
MultiValue, NoAlias, Unique, and init now work with Python 2
1.4.1
=====
Py3: added Enum creation flags: Auto, MultiValue, NoAlias, Unique
fixed extend_enum to honor Enum flags
1.4.0
=====
When possible aenum inherits from Python's own enum.
Breaking change: enum members now default to evaluating as True to maintain
compatibility with the stdlib.
Add your own __bool__ (__nonzero__ in Python 2) if need this behavior:
def __bool__(self):
return bool(self.value)
__nonzero__ = __bool__
|