Skip to content

Commit 211b8d0

Browse files
authored
Merge pull request #64 from bckohan/v2.x.x
V2.0.0
2 parents b182cf2 + 577bb8c commit 211b8d0

File tree

11 files changed

+2987
-189
lines changed

11 files changed

+2987
-189
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ Add properties to Python enumeration values with a simple declarative syntax. [E
1414

1515
```python
1616

17-
from enum_properties import EnumProperties, p
17+
import typing as t
18+
from enum_properties import EnumProperties
1819
from enum import auto
1920

20-
class Color(EnumProperties, p('rgb'), p('hex')):
21+
class Color(EnumProperties):
22+
23+
rgb: t.Tuple[int, int, int]
24+
hex: str
2125

2226
# name value rgb hex
2327
RED = auto(), (1, 0, 0), 'ff0000'
@@ -37,27 +41,25 @@ Add properties to Python enumeration values with a simple declarative syntax. [E
3741

3842
```
3943

40-
Properties may also be symmetrically mapped to enumeration values using s() values and type hints
41-
are optional for better dev experience:
44+
Properties may also be symmetrically mapped to enumeration values using annotated type hints:
4245

4346
```python
4447

4548
import typing as t
46-
from enum_properties import EnumProperties, s
49+
from enum_properties import EnumProperties, Symmetric
4750
from enum import auto
4851

49-
class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):
52+
class Color(EnumProperties):
5053

51-
rgb: t.Tuple[int, int, int]
52-
hex: str
54+
rgb: t.Annotated[t.Tuple[int, int, int], Symmetric()]
55+
hex: t.Annotated[str, Symmetric(case_fold=True)]
5356

5457
RED = auto(), (1, 0, 0), 'ff0000'
5558
GREEN = auto(), (0, 1, 0), '00ff00'
5659
BLUE = auto(), (0, 0, 1), '0000ff'
5760

58-
# any named s() values in the Enum's inheritance become properties on
59-
# each value, and the enumeration value may be instantiated from the
60-
# property's value
61+
# Enumeration instances may be instantiated from any Symmetric property
62+
# values. Use case_fold for case insensitive matching
6163

6264
Color((1, 0, 0)) == Color.RED
6365
Color((0, 1, 0)) == Color.GREEN

doc/source/changelog.rst

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,48 @@
22
Change Log
33
==========
44

5-
v1.8.1
6-
======
5+
v2.0.0 (02-SEP-2024)
6+
====================
7+
8+
* Implemented `Allow properties to be specified through type hints alone without s/p value inheritance <https://github.com/bckohan/enum-properties/issues/60>`_
9+
10+
v1.8.1 (29-AUG-2024)
11+
====================
712

813
* Fixed `Add missing py.typed <https://github.com/bckohan/enum-properties/issues/62>`_
914

10-
v1.8.0
11-
======
15+
v1.8.0 (26-AUG-2024)
16+
====================
1217

1318
* Implemented `Drop support for Python 3.7 <https://github.com/bckohan/enum-properties/issues/59>`_
1419
* Implemented `Support Python 3.13 <https://github.com/bckohan/enum-properties/issues/58>`_
1520
* Implemented `Move to ruff for linting and formatting. <https://github.com/bckohan/enum-properties/issues/57>`_
1621
* Documented `Support type hinting for properties <https://github.com/bckohan/enum-properties/issues/42>`_
1722

18-
v1.7.0
19-
======
23+
v1.7.0 (02-OCT-2023)
24+
====================
25+
2026
* Implemented `Add a StrEnumProperties type to match StrEnum. <https://github.com/bckohan/enum-properties/issues/54>`_
2127
* Fixed `Hash equivalency between values and enums is broken. <https://github.com/bckohan/enum-properties/issues/53>`_
2228
* Implemented `Test mixed primitive type values. <https://github.com/bckohan/enum-properties/issues/46>`_
2329

24-
v1.6.0
25-
======
30+
v1.6.0 (22-AUG-2023)
31+
====================
32+
2633
* Implemented `Support dataclasses in enums along with Python 3.12 <https://github.com/bckohan/enum-properties/issues/52>`_
2734

28-
v1.5.2
29-
======
35+
v1.5.2 (06-MAY-2023)
36+
====================
3037

3138
* Fixed `_missing_ allows exceptions through that are not ValueError, TypeError or KeyError <https://github.com/bckohan/enum-properties/issues/47>`_
3239

33-
v1.5.1
34-
======
40+
v1.5.1 (17-APR-2023)
41+
====================
3542

3643
* Fixed `Symmetric string 'none' values enable coercion from None despite match_none=False <https://github.com/bckohan/enum-properties/issues/45>`_
3744

38-
v1.5.0
39-
======
45+
v1.5.0 (15-APR-2023)
46+
====================
4047

4148
There is one minimally impactful breaking change in the 1.5.0 release:
4249

@@ -49,8 +56,8 @@ The 1.5.0 release includes two feature improvements:
4956
* Implemented `Configurable behavior for matching none on symmetric fields <https://github.com/bckohan/enum-properties/issues/44>`_
5057
* Implemented `Allow @specialize to accept a list of enumeration values. <https://github.com/bckohan/enum-properties/issues/43>`_
5158

52-
v1.4.0
53-
======
59+
v1.4.0 (08-APR-2023)
60+
====================
5461

5562
There are some breaking changes in the 1.4.0 release:
5663

@@ -73,68 +80,68 @@ been reduced by about 1/3.
7380
* Fixed `New flag behavior modifiers break IntFlagProperties in python 3.11+ <https://github.com/bckohan/enum-properties/issues/37>`_
7481

7582

76-
v1.3.3
77-
======
83+
v1.3.3 (15-FEB-2023)
84+
====================
7885

7986
* Fixed `LICENSE included in source package. <https://github.com/bckohan/enum-properties/issues/30>`_
8087

8188

82-
v1.3.2
83-
======
89+
v1.3.2 (15-FEB-2023)
90+
====================
8491

8592
* Fixed `Nested classes are incompatible with EnumProperties. <https://github.com/bckohan/enum-properties/issues/29>`_
8693

8794

88-
v1.3.1
89-
======
95+
v1.3.1 (25-OCT-2022)
96+
====================
9097

9198
* Fixed `Remove errant print statement <https://github.com/bckohan/enum-properties/issues/20>`_
9299

93100

94-
v1.3.0
95-
======
101+
v1.3.0 (25-OCT-2022)
102+
====================
96103

97104
* Fixed `Initialize Flag enum with empty iterable should resolve to Flag(0) - no selections. <https://github.com/bckohan/enum-properties/issues/19>`_
98105
* Added `Support for python 3.11. <https://github.com/bckohan/enum-properties/issues/18>`_
99106
* Implemented `Generally allow composite flag enumerations to be treated as iterables of active flags. <https://github.com/bckohan/enum-properties/issues/17>`_
100107

101-
v1.2.2
102-
======
108+
v1.2.2 (25-OCT-2022)
109+
====================
103110

104111
* Implemented `Add convenience property to decompose Flag enumeration values <https://github.com/bckohan/enum-properties/issues/16>`_
105112

106-
v1.2.1
107-
======
113+
v1.2.1 (25-OCT-2022)
114+
====================
108115

109116
* Implemented `Allow Flag Enumerations to be created from iterables <https://github.com/bckohan/enum-properties/issues/15>`_
110117

111-
v1.2.0
112-
======
118+
v1.2.0 (17-AUG-2022)
119+
====================
113120

114121
* Implemented `Drop support for < Python3.6 <https://github.com/bckohan/enum-properties/issues/6>`_
115122
* Fixed `Add types and support for Flag and IntFlag <https://github.com/bckohan/enum-properties/issues/5>`_
116123

117-
v1.1.1
118-
======
124+
v1.1.1 (24-JUL-2022)
125+
====================
119126

120127
* Fixed `SymmetricMixin objects are not hashable <https://github.com/bckohan/enum-properties/issues/4>`_
121128

122-
v1.1.0
123-
======
129+
v1.1.0 (23-JUL-2022)
130+
====================
124131

125132
* Implemented `Provide equality comparisons for symmetric property values <https://github.com/bckohan/enum-properties/issues/3>`_
126133

127-
v1.0.2
128-
======
134+
v1.0.2 (19-JUL-2022)
135+
====================
129136

130137
* Fixed `Consolidate source files <https://github.com/bckohan/enum-properties/issues/1>`_
131138

132-
v1.0.1
133-
======
139+
v1.0.1 (18-JUL-2022)
140+
====================
134141

135142
* Include readme in package
136143

137-
v1.0.0
138-
======
144+
v1.0.0 (18-JUL-2022)
145+
====================
139146

140147
* Initial Release (production/stable)

doc/source/examples.rst

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ enumeration. We might implement it like so:
2424

2525
.. code-block:: python
2626
27-
class AddressRoute(
28-
EnumProperties,
29-
s('abbr', case_fold=True),
30-
s('alt', case_fold=True)
31-
):
27+
import typing as t
28+
from enum_properties import EnumProperties, Symmetric
3229
33-
_symmetric_builtins_ = [s('name', case_fold=True)]
30+
class AddressRoute(EnumProperties):
31+
32+
# name is a builtin property of Enum, we can override its case insensitivity
33+
name: t.Annotated[str, Symmetric(case_fold=True)]
34+
35+
abbr: t.Annotated[str, Symmetric(case_fold=True)]
36+
alt: t.Annotated[t.List[str], Symmetric(case_fold=True)]
3437
3538
# name value abbr alt
3639
ALLEY = 1, 'ALY', ['ALLEE', 'ALLY']
@@ -73,18 +76,20 @@ implement our style enumeration like so:
7376

7477
.. code-block:: python
7578
76-
class MapBoxStyle(
77-
EnumProperties,
78-
s('label', case_fold=True),
79-
p('version')
80-
):
79+
import typing as t
80+
from enum_properties import EnumProperties, s, Symmetric
81+
82+
class MapBoxStyle(EnumProperties):
8183
"""
8284
https://docs.mapbox.com/api/maps/styles/
8385
"""
84-
_symmetric_builtins_ = ['name', 'uri']
86+
87+
# we may mark builtins and normal properties as symmetric using
88+
# the _symmetric_builtins_ attribute
89+
_symmetric_builtins_ = [s('name', case_fold=True), 'uri']
8590
8691
# type hints are optional for better dev experience
87-
label: str
92+
label: t.Annotated[str, Symmetric(case_fold=True)]
8893
version: int
8994
9095
# name value label version

doc/source/index.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ Enum Properties is a lightweight extension to Python's Enum_ class. Example:
99

1010
.. code:: python
1111
12-
from enum_properties import EnumProperties, p
12+
import typing as t
13+
from enum_properties import EnumProperties
1314
from enum import auto
1415
15-
class Color(EnumProperties, p('rgb'), p('hex')):
16+
class Color(EnumProperties):
17+
18+
rgb: t.Tuple[int, int, int]
19+
hex: str
1620
1721
# name value rgb hex
1822
RED = auto(), (1, 0, 0), 'ff0000'
1923
GREEN = auto(), (0, 1, 0), '00ff00'
2024
BLUE = auto(), (0, 0, 1), '0000ff'
2125
22-
# the named p() values in the Enum's inheritance become properties on
26+
# the type hints on the Enum class become properties on
2327
# each value, matching the order in which they are specified
2428
2529
Color.RED.rgb == (1, 0, 0)
@@ -31,26 +35,25 @@ Enum Properties is a lightweight extension to Python's Enum_ class. Example:
3135
Color.BLUE.hex == '0000ff'
3236
3337
Properties may also be symmetrically mapped to enumeration values using
34-
s() values and type hints are optional for better dev experience:
38+
Symmetric type annotations:
3539

3640
.. code:: python
3741
3842
import typing as t
39-
from enum_properties import EnumProperties, s
43+
from enum_properties import EnumProperties, Symmetric
4044
from enum import auto
4145
4246
class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):
4347
44-
rgb: t.Tuple[int, int, int]
45-
hex: str
48+
rgb: t.Annotated[t.Tuple[int, int, int], Symmetric()]
49+
hex: t.Annotated[str, Symmetric(case_fold=True)]
4650
4751
RED = auto(), (1, 0, 0), 'ff0000'
4852
GREEN = auto(), (0, 1, 0), '00ff00'
4953
BLUE = auto(), (0, 0, 1), '0000ff'
5054
51-
# any named s() values in the Enum's inheritance become properties on
52-
# each value, and the enumeration value may be instantiated from the
53-
# property's value
55+
# Enumeration instances may be instantiated from any Symmetric property
56+
# values. Use case_fold for case insensitive matching
5457
5558
Color((1, 0, 0)) == Color.RED
5659
Color((0, 1, 0)) == Color.GREEN

0 commit comments

Comments
 (0)