Skip to content

Commit

Permalink
Merge pull request #64 from bckohan/v2.x.x
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
bckohan authored Sep 3, 2024
2 parents b182cf2 + 577bb8c commit 211b8d0
Show file tree
Hide file tree
Showing 11 changed files with 2,987 additions and 189 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ Add properties to Python enumeration values with a simple declarative syntax. [E

```python

from enum_properties import EnumProperties, p
import typing as t
from enum_properties import EnumProperties
from enum import auto

class Color(EnumProperties, p('rgb'), p('hex')):
class Color(EnumProperties):

rgb: t.Tuple[int, int, int]
hex: str

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

```

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

```python

import typing as t
from enum_properties import EnumProperties, s
from enum_properties import EnumProperties, Symmetric
from enum import auto

class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):
class Color(EnumProperties):

rgb: t.Tuple[int, int, int]
hex: str
rgb: t.Annotated[t.Tuple[int, int, int], Symmetric()]
hex: t.Annotated[str, Symmetric(case_fold=True)]

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

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

Color((1, 0, 0)) == Color.RED
Color((0, 1, 0)) == Color.GREEN
Expand Down
87 changes: 47 additions & 40 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,48 @@
Change Log
==========

v1.8.1
======
v2.0.0 (02-SEP-2024)
====================

* Implemented `Allow properties to be specified through type hints alone without s/p value inheritance <https://github.com/bckohan/enum-properties/issues/60>`_

v1.8.1 (29-AUG-2024)
====================

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

v1.8.0
======
v1.8.0 (26-AUG-2024)
====================

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

v1.7.0
======
v1.7.0 (02-OCT-2023)
====================

* Implemented `Add a StrEnumProperties type to match StrEnum. <https://github.com/bckohan/enum-properties/issues/54>`_
* Fixed `Hash equivalency between values and enums is broken. <https://github.com/bckohan/enum-properties/issues/53>`_
* Implemented `Test mixed primitive type values. <https://github.com/bckohan/enum-properties/issues/46>`_

v1.6.0
======
v1.6.0 (22-AUG-2023)
====================

* Implemented `Support dataclasses in enums along with Python 3.12 <https://github.com/bckohan/enum-properties/issues/52>`_

v1.5.2
======
v1.5.2 (06-MAY-2023)
====================

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

v1.5.1
======
v1.5.1 (17-APR-2023)
====================

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

v1.5.0
======
v1.5.0 (15-APR-2023)
====================

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

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

v1.4.0
======
v1.4.0 (08-APR-2023)
====================

There are some breaking changes in the 1.4.0 release:

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


v1.3.3
======
v1.3.3 (15-FEB-2023)
====================

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


v1.3.2
======
v1.3.2 (15-FEB-2023)
====================

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


v1.3.1
======
v1.3.1 (25-OCT-2022)
====================

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


v1.3.0
======
v1.3.0 (25-OCT-2022)
====================

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

v1.2.2
======
v1.2.2 (25-OCT-2022)
====================

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

v1.2.1
======
v1.2.1 (25-OCT-2022)
====================

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

v1.2.0
======
v1.2.0 (17-AUG-2022)
====================

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

v1.1.1
======
v1.1.1 (24-JUL-2022)
====================

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

v1.1.0
======
v1.1.0 (23-JUL-2022)
====================

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

v1.0.2
======
v1.0.2 (19-JUL-2022)
====================

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

v1.0.1
======
v1.0.1 (18-JUL-2022)
====================

* Include readme in package

v1.0.0
======
v1.0.0 (18-JUL-2022)
====================

* Initial Release (production/stable)
31 changes: 18 additions & 13 deletions doc/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ enumeration. We might implement it like so:

.. code-block:: python
class AddressRoute(
EnumProperties,
s('abbr', case_fold=True),
s('alt', case_fold=True)
):
import typing as t
from enum_properties import EnumProperties, Symmetric
_symmetric_builtins_ = [s('name', case_fold=True)]
class AddressRoute(EnumProperties):
# name is a builtin property of Enum, we can override its case insensitivity
name: t.Annotated[str, Symmetric(case_fold=True)]
abbr: t.Annotated[str, Symmetric(case_fold=True)]
alt: t.Annotated[t.List[str], Symmetric(case_fold=True)]
# name value abbr alt
ALLEY = 1, 'ALY', ['ALLEE', 'ALLY']
Expand Down Expand Up @@ -73,18 +76,20 @@ implement our style enumeration like so:

.. code-block:: python
class MapBoxStyle(
EnumProperties,
s('label', case_fold=True),
p('version')
):
import typing as t
from enum_properties import EnumProperties, s, Symmetric
class MapBoxStyle(EnumProperties):
"""
https://docs.mapbox.com/api/maps/styles/
"""
_symmetric_builtins_ = ['name', 'uri']
# we may mark builtins and normal properties as symmetric using
# the _symmetric_builtins_ attribute
_symmetric_builtins_ = [s('name', case_fold=True), 'uri']
# type hints are optional for better dev experience
label: str
label: t.Annotated[str, Symmetric(case_fold=True)]
version: int
# name value label version
Expand Down
23 changes: 13 additions & 10 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ Enum Properties is a lightweight extension to Python's Enum_ class. Example:

.. code:: python
from enum_properties import EnumProperties, p
import typing as t
from enum_properties import EnumProperties
from enum import auto
class Color(EnumProperties, p('rgb'), p('hex')):
class Color(EnumProperties):
rgb: t.Tuple[int, int, int]
hex: str
# name value rgb hex
RED = auto(), (1, 0, 0), 'ff0000'
GREEN = auto(), (0, 1, 0), '00ff00'
BLUE = auto(), (0, 0, 1), '0000ff'
# the named p() values in the Enum's inheritance become properties on
# the type hints on the Enum class become properties on
# each value, matching the order in which they are specified
Color.RED.rgb == (1, 0, 0)
Expand All @@ -31,26 +35,25 @@ Enum Properties is a lightweight extension to Python's Enum_ class. Example:
Color.BLUE.hex == '0000ff'
Properties may also be symmetrically mapped to enumeration values using
s() values and type hints are optional for better dev experience:
Symmetric type annotations:

.. code:: python
import typing as t
from enum_properties import EnumProperties, s
from enum_properties import EnumProperties, Symmetric
from enum import auto
class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):
rgb: t.Tuple[int, int, int]
hex: str
rgb: t.Annotated[t.Tuple[int, int, int], Symmetric()]
hex: t.Annotated[str, Symmetric(case_fold=True)]
RED = auto(), (1, 0, 0), 'ff0000'
GREEN = auto(), (0, 1, 0), '00ff00'
BLUE = auto(), (0, 0, 1), '0000ff'
# any named s() values in the Enum's inheritance become properties on
# each value, and the enumeration value may be instantiated from the
# property's value
# Enumeration instances may be instantiated from any Symmetric property
# values. Use case_fold for case insensitive matching
Color((1, 0, 0)) == Color.RED
Color((0, 1, 0)) == Color.GREEN
Expand Down
Loading

0 comments on commit 211b8d0

Please sign in to comment.