enumplus 1.2.1__tar.gz → 1.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {enumplus-1.2.1 → enumplus-1.2.3}/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- {enumplus-1.2.1 → enumplus-1.2.3}/.github/ISSUE_TEMPLATE/config.yml +2 -2
- {enumplus-1.2.1 → enumplus-1.2.3}/.github/workflows/release.yml +0 -1
- {enumplus-1.2.1 → enumplus-1.2.3}/AGENTS.md +27 -6
- {enumplus-1.2.1 → enumplus-1.2.3}/CHANGELOG.md +69 -6
- {enumplus-1.2.1 → enumplus-1.2.3}/CONTRIBUTING.md +4 -4
- {enumplus-1.2.1 → enumplus-1.2.3}/LICENSE +1 -1
- {enumplus-1.2.1 → enumplus-1.2.3}/PKG-INFO +25 -16
- {enumplus-1.2.1 → enumplus-1.2.3}/README.md +21 -12
- {enumplus-1.2.1 → enumplus-1.2.3}/SUPPORT.md +4 -4
- {enumplus-1.2.1 → enumplus-1.2.3}/enumplus/enum.py +158 -42
- {enumplus-1.2.1 → enumplus-1.2.3}/enumplus/pydantic.py +2 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/enumplus/serialize.py +10 -3
- {enumplus-1.2.1 → enumplus-1.2.3}/pyproject.toml +5 -4
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_compatibility.py +1 -1
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_edge_cases.py +412 -1
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_enum.py +2 -2
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_metadata_unpacking.py +39 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_public_api.py +8 -2
- enumplus-1.2.1/.github/FUNDING.yml +0 -3
- {enumplus-1.2.1 → enumplus-1.2.3}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/.github/workflows/ci.yml +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/.gitignore +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/CODE_OF_CONDUCT.md +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/SECURITY.md +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/enumplus/__init__.py +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/enumplus/py.typed +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/__init__.py +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_new_features.py +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_ordered.py +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_pydantic.py +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_serialize.py +0 -0
- {enumplus-1.2.1 → enumplus-1.2.3}/tests/test_type_hints.py +0 -0
|
@@ -31,7 +31,7 @@ A clear and concise description of what actually happened.
|
|
|
31
31
|
## Environment
|
|
32
32
|
|
|
33
33
|
- Python version: [e.g. 3.12.1]
|
|
34
|
-
- enumplus version: [e.g. 1.1
|
|
34
|
+
- enumplus version: [e.g. 1.2.1]
|
|
35
35
|
- OS: [e.g. Ubuntu 22.04, Windows 11, macOS 14]
|
|
36
36
|
|
|
37
37
|
## Additional context
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
blank_issues_enabled: false
|
|
2
2
|
contact_links:
|
|
3
3
|
- name: GitHub Discussions
|
|
4
|
-
url: https://github.com/MathiasPaulenko/
|
|
4
|
+
url: https://github.com/MathiasPaulenko/enumplus/discussions
|
|
5
5
|
about: Ask questions and discuss ideas with the community.
|
|
6
6
|
- name: Security Policy
|
|
7
|
-
url: https://github.com/MathiasPaulenko/
|
|
7
|
+
url: https://github.com/MathiasPaulenko/enumplus/blob/main/SECURITY.md
|
|
8
8
|
about: Report security vulnerabilities privately — do not open a public issue.
|
|
@@ -96,7 +96,6 @@ jobs:
|
|
|
96
96
|
DOCS=$(git log --pretty=format:"- %s" ${RANGE} --grep="^docs" --grep="^readme" -i || true)
|
|
97
97
|
TESTS=$(git log --pretty=format:"- %s" ${RANGE} --grep="^test" -i || true)
|
|
98
98
|
CHORE=$(git log --pretty=format:"- %s" ${RANGE} --grep="^chore" --grep="^ci" --grep="^build" -i || true)
|
|
99
|
-
RELEASE=$(git log --pretty=format:"- %s" ${RANGE} --grep="^release" -i || true)
|
|
100
99
|
|
|
101
100
|
{
|
|
102
101
|
echo "body<<EOF"
|
|
@@ -22,9 +22,30 @@ Requires Python `>=3.11`.
|
|
|
22
22
|
- Keep class config keys such as `serialize_by_name` from becoming enum members
|
|
23
23
|
or affecting `auto()` generation.
|
|
24
24
|
- Support `auto()` following a metadata tuple on Python 3.11–3.14.
|
|
25
|
-
- `
|
|
26
|
-
`
|
|
27
|
-
|
|
25
|
+
- `serialize_by_name` is a reserved class config key: it must be a `bool`
|
|
26
|
+
(`TypeError` otherwise) and can never be a member name.
|
|
27
|
+
- Metadata tuples are detected with `type(value) is tuple` (not
|
|
28
|
+
`isinstance`), so tuple subclasses such as `NamedTuple` stay intact as
|
|
29
|
+
member values.
|
|
30
|
+
- During class creation, `EnumMeta.__new__` injects the collected metadata map
|
|
31
|
+
as the temporary `_enumplus_pending_metadata` class attribute and removes it
|
|
32
|
+
after member post-processing. `Enum._resolve_metadata()` reads `_metadata_`
|
|
33
|
+
first, then the pending map, so `label`/`metadata`/metadata attributes work
|
|
34
|
+
inside member `__init__`. Members created via `enum._simple_enum` never get
|
|
35
|
+
`_metadata_`/`_label_`/`_index_`; accessors degrade gracefully to auto
|
|
36
|
+
labels, empty metadata, and `_sort_order_`-based ordering.
|
|
37
|
+
- Auto-generated labels use `name.replace("_", " ").title()`. `filter(label=...)`
|
|
38
|
+
matches the evaluated label, not the raw metadata dict.
|
|
39
|
+
- `Enum.__eq__` compares enum-to-enum by identity links only (`self is other`,
|
|
40
|
+
`self.value is other`, `other.value is self`) and everything else through
|
|
41
|
+
`_safe_equal`, which coerces `a == b` to a `bool` without raising on
|
|
42
|
+
shape/length mismatches (e.g. NumPy arrays, unhashable container values).
|
|
43
|
+
`EnumMeta.__contains__`, `from_value()`, `is_valid()`, and `_missing_()`
|
|
44
|
+
share `_match_enum_member` for the enum-member branch.
|
|
45
|
+
- `Enum._missing_` is implemented so `cls(value)` lookup agrees with
|
|
46
|
+
`from_value()` on misses. For classes mixing in `enum.Flag`/`enum.IntFlag`
|
|
47
|
+
it delegates to the nearest Flag-family `_missing_` in the MRO, preserving
|
|
48
|
+
composite pseudo-members and `boundary=` semantics.
|
|
28
49
|
- `Enum.__hash__` uses `hash(self.value)` when possible and falls back to
|
|
29
50
|
`id(self)` for unhashable values, so enum members with list/dict values are
|
|
30
51
|
still usable as dict keys.
|
|
@@ -67,7 +88,7 @@ py -3.11 -m mypy --strict enumplus/ tests/
|
|
|
67
88
|
|
|
68
89
|
## Known constraints
|
|
69
90
|
|
|
70
|
-
- The
|
|
71
|
-
project
|
|
72
|
-
|
|
91
|
+
- The repository was renamed from `enumpy` to `enumplus` on GitHub. All
|
|
92
|
+
project URLs point to `MathiasPaulenko/enumplus`; old `enumpy` links
|
|
93
|
+
redirect automatically.
|
|
73
94
|
- `ref/` is intentionally ignored (local reference material). Do not commit it.
|
|
@@ -5,7 +5,68 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [1.2.3] - 2026-11-18
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- `label`, `metadata`, and metadata attributes are now readable inside a
|
|
13
|
+
member's `__init__`. stdlib runs `__init__` during class creation, before
|
|
14
|
+
`EnumMeta.__new__` could attach `_metadata_`; metadata is now resolved
|
|
15
|
+
through a pending map while the class is being built.
|
|
16
|
+
- Members created via `enum._simple_enum` no longer raise `AttributeError` on
|
|
17
|
+
`label`, `metadata`, metadata attributes, `filter()`, `to_dict()`,
|
|
18
|
+
`to_json()`, or `OrderedEnum` comparisons. They fall back to auto-generated
|
|
19
|
+
labels, empty metadata, and the stdlib `_sort_order_` for ordering.
|
|
20
|
+
- Member values that are tuple subclasses (e.g. `NamedTuple` instances) are no
|
|
21
|
+
longer mistaken for `(value, metadata)` tuples and unwrapped. Only plain
|
|
22
|
+
`tuple` values are treated as metadata declarations.
|
|
23
|
+
- `member == other` now returns `True` when `other` is this member's value
|
|
24
|
+
object or wraps it as its value, symmetrically in both directions. Equality
|
|
25
|
+
and hashing stay consistent: `Outer.A == Inner.X` now agrees with
|
|
26
|
+
`Outer.A == "x"` when `Outer.A.value is Inner.X`.
|
|
27
|
+
- `cls(value)` lookup now delegates misses to a `_missing_` hook that uses the
|
|
28
|
+
same safe equality as `from_value()`, so call-style lookup and
|
|
29
|
+
`from_value()` agree. Classes mixing in `enum.Flag`/`enum.IntFlag` keep the
|
|
30
|
+
stdlib lookup, so composite values (`F.A | F.B`) and `boundary=` handling
|
|
31
|
+
still work.
|
|
32
|
+
- `in`, `from_value()`, and `is_valid()` now also match a foreign enum member
|
|
33
|
+
whose own value is a member of the queried enum (e.g. `Outer.A in Inner`
|
|
34
|
+
when `Outer.A.value is Inner.X`), consistent with member equality.
|
|
35
|
+
- `map()` raises `TypeError` for non-mapping arguments instead of
|
|
36
|
+
`AttributeError`.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- Removed `@dataclass_transform()` from the metaclass. It made type checkers
|
|
41
|
+
require `_metadata_`/`_index_` constructor arguments on calls like
|
|
42
|
+
`Color("red")`. Metadata attribute access still resolves through
|
|
43
|
+
`__getattr__` and is typed as `Any`.
|
|
44
|
+
|
|
45
|
+
## [1.2.2] - 2026-10-06
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- `from_value()`, `get()`, and `validate()` now return the member itself when
|
|
50
|
+
passed a member of the queried enum whose value is a foreign enum member.
|
|
51
|
+
Previously they raised `ValueError` (or returned the default) even though
|
|
52
|
+
`is_valid()` and `in` correctly accepted the member.
|
|
53
|
+
- `is_valid()` and `from_value()` now accept members of subclass enums, matching
|
|
54
|
+
the behavior of `in` (e.g. `Base.is_valid(Child.MEMBER)` is `True` for an
|
|
55
|
+
empty `Base`).
|
|
56
|
+
- `SerializableEncoder` now also serializes stdlib `enum.Enum` members, not just
|
|
57
|
+
enumplus members. `to_json()` and `json.dumps()` no longer raise `TypeError`
|
|
58
|
+
when a member's value or metadata is a stdlib enum member.
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
|
|
62
|
+
- Auto-generated labels now replace underscores with spaces: `IN_PROGRESS`
|
|
63
|
+
produces `"In Progress"` instead of `"In_Progress"`.
|
|
64
|
+
- `filter(label=...)` now matches against the member's evaluated label, so
|
|
65
|
+
callable and auto-generated labels can be filtered.
|
|
66
|
+
- `serialize_by_name` now raises `TypeError` when set to a non-`bool` value
|
|
67
|
+
instead of being silently swallowed as a member assignment.
|
|
68
|
+
- `OrderedEnum` comparison operators are now typed as returning
|
|
69
|
+
`bool | NotImplementedType`.
|
|
9
70
|
|
|
10
71
|
## [1.2.1] - 2026-08-23
|
|
11
72
|
|
|
@@ -84,8 +145,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
84
145
|
- Pydantic v2 integration via `__get_pydantic_core_schema__`.
|
|
85
146
|
- Full test suite, CI, and release workflows.
|
|
86
147
|
|
|
87
|
-
[Unreleased]: https://github.com/MathiasPaulenko/
|
|
88
|
-
[1.2.
|
|
89
|
-
[1.2.
|
|
90
|
-
[1.1
|
|
91
|
-
[1.
|
|
148
|
+
[Unreleased]: https://github.com/MathiasPaulenko/enumplus/compare/v1.2.3...HEAD
|
|
149
|
+
[1.2.3]: https://github.com/MathiasPaulenko/enumplus/releases/tag/v1.2.3
|
|
150
|
+
[1.2.2]: https://github.com/MathiasPaulenko/enumplus/releases/tag/v1.2.2
|
|
151
|
+
[1.2.1]: https://github.com/MathiasPaulenko/enumplus/releases/tag/v1.2.1
|
|
152
|
+
[1.2.0]: https://github.com/MathiasPaulenko/enumplus/releases/tag/v1.2.0
|
|
153
|
+
[1.1.0]: https://github.com/MathiasPaulenko/enumplus/releases/tag/v1.1.0
|
|
154
|
+
[1.0.0]: https://github.com/MathiasPaulenko/enumplus/releases/tag/v1.0.0
|
|
@@ -7,8 +7,8 @@ Thank you for your interest in contributing to enumplus! This document describes
|
|
|
7
7
|
1. Fork the repository on GitHub.
|
|
8
8
|
2. Clone your fork locally:
|
|
9
9
|
```bash
|
|
10
|
-
git clone https://github.com/<your-username>/
|
|
11
|
-
cd
|
|
10
|
+
git clone https://github.com/<your-username>/enumplus.git
|
|
11
|
+
cd enumplus
|
|
12
12
|
```
|
|
13
13
|
3. Create a virtual environment and install dev dependencies:
|
|
14
14
|
```bash
|
|
@@ -17,7 +17,7 @@ Thank you for your interest in contributing to enumplus! This document describes
|
|
|
17
17
|
pip install -e ".[dev]"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
> **Note:** The
|
|
20
|
+
> **Note:** The repository was previously named `enumpy`; it has been renamed to `enumplus` to match the package name. Old links redirect automatically.
|
|
21
21
|
|
|
22
22
|
## Development Workflow
|
|
23
23
|
|
|
@@ -73,7 +73,7 @@ py -3.11 -m mypy --strict enumplus/ tests/
|
|
|
73
73
|
|
|
74
74
|
## Reporting Issues
|
|
75
75
|
|
|
76
|
-
- Use [GitHub Issues](https://github.com/MathiasPaulenko/
|
|
76
|
+
- Use [GitHub Issues](https://github.com/MathiasPaulenko/enumplus/issues) to report bugs or request features.
|
|
77
77
|
- Use the provided issue templates for consistency.
|
|
78
78
|
|
|
79
79
|
## Code of Conduct
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: enumplus
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.3
|
|
4
4
|
Summary: Enhanced Python enums with metadata, serialization, and choices
|
|
5
5
|
Project-URL: Homepage, https://pypi.org/project/enumplus/
|
|
6
|
-
Project-URL: Repository, https://github.com/MathiasPaulenko/
|
|
7
|
-
Project-URL: Issues, https://github.com/MathiasPaulenko/
|
|
8
|
-
Project-URL: Changelog, https://github.com/MathiasPaulenko/
|
|
6
|
+
Project-URL: Repository, https://github.com/MathiasPaulenko/enumplus
|
|
7
|
+
Project-URL: Issues, https://github.com/MathiasPaulenko/enumplus/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/MathiasPaulenko/enumplus/blob/main/CHANGELOG.md
|
|
9
9
|
Author-email: Mathias Paulenko <mathias.paulenko@outlook.com>
|
|
10
10
|
License-Expression: MIT
|
|
11
11
|
License-File: LICENSE
|
|
@@ -36,7 +36,7 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|

|
|
37
37
|

|
|
38
38
|

|
|
39
|
-

|
|
40
40
|
|
|
41
41
|
Python's `enum.Enum` is basic. `enumplus` adds display names, metadata, JSON
|
|
42
42
|
serialization, `choices()`, and value-based comparison — all with zero runtime
|
|
@@ -125,12 +125,12 @@ print("red" in Color) # True
|
|
|
125
125
|
|
|
126
126
|
### Display Names (label)
|
|
127
127
|
|
|
128
|
-
Every member gets a human-readable label, auto-generated from the member name or set explicitly via metadata.
|
|
128
|
+
Every member gets a human-readable label, auto-generated from the member name or set explicitly via metadata. Auto-generated labels replace underscores with spaces (`IN_PROGRESS` becomes `"In Progress"`).
|
|
129
129
|
|
|
130
130
|
```python
|
|
131
131
|
class Status(Enum):
|
|
132
|
-
PENDING = "pending"
|
|
133
|
-
IN_PROGRESS =
|
|
132
|
+
PENDING = "pending" # label: "Pending"
|
|
133
|
+
IN_PROGRESS = "in_progress" # label: "In Progress"
|
|
134
134
|
|
|
135
135
|
print(Status.PENDING.label) # "Pending"
|
|
136
136
|
print(Status.IN_PROGRESS.label) # "In Progress"
|
|
@@ -220,7 +220,7 @@ Color.keys() # ["RED", "GREEN"]
|
|
|
220
220
|
|
|
221
221
|
### filter()
|
|
222
222
|
|
|
223
|
-
Filter members by metadata key-value pairs (AND logic).
|
|
223
|
+
Filter members by metadata key-value pairs (AND logic). `label` is special: it matches against the evaluated label (including auto-generated and callable labels), not the raw metadata dict.
|
|
224
224
|
|
|
225
225
|
```python
|
|
226
226
|
class Color(Enum):
|
|
@@ -230,6 +230,7 @@ class Color(Enum):
|
|
|
230
230
|
Color.filter(category="warm") # [Color.RED]
|
|
231
231
|
Color.filter(hex="#FF0000", category="warm") # [Color.RED]
|
|
232
232
|
Color.filter() # [Color.RED, Color.GREEN]
|
|
233
|
+
Color.filter(label="Red") # [Color.RED]
|
|
233
234
|
```
|
|
234
235
|
|
|
235
236
|
### Comparison with values (==)
|
|
@@ -433,24 +434,21 @@ print(Color.labels()) # ["Rojo", "Verde"]
|
|
|
433
434
|
print(Color.choices()) # [("red", "Rojo"), ("green", "Verde")]
|
|
434
435
|
```
|
|
435
436
|
|
|
436
|
-
Callable labels work everywhere: `choices()`, `to_dict()`, `to_json()`, `labels()`, and `str()`.
|
|
437
|
+
Callable labels work everywhere: `choices()`, `to_dict()`, `to_json()`, `labels()`, `filter(label=...)`, and `str()`.
|
|
437
438
|
|
|
438
439
|
### Type hints in metadata
|
|
439
440
|
|
|
440
|
-
|
|
441
|
+
Metadata attributes are resolved at runtime through `__getattr__`, which
|
|
442
|
+
returns `Any`. Type checkers therefore accept `member.<key>` accesses as
|
|
443
|
+
`Any`, but cannot verify individual key names or value types.
|
|
441
444
|
|
|
442
445
|
```python
|
|
443
446
|
class Color(Enum):
|
|
444
447
|
RED = ("red", {"hex": "#FF0000"})
|
|
445
448
|
|
|
446
|
-
# Type checkers recognize .hex as a valid attribute
|
|
447
449
|
Color.RED.hex # inferred as Any via __getattr__
|
|
448
450
|
```
|
|
449
451
|
|
|
450
|
-
> **Note:** Type inference for metadata attributes depends on the type checker.
|
|
451
|
-
> The `@dataclass_transform()` decorator provides the structural hint, but
|
|
452
|
-
> runtime attribute access goes through `__getattr__`, which returns `Any`.
|
|
453
|
-
|
|
454
452
|
## Migration from stdlib
|
|
455
453
|
|
|
456
454
|
Just change one import:
|
|
@@ -465,6 +463,17 @@ from enumplus import Enum
|
|
|
465
463
|
|
|
466
464
|
All existing enum code continues to work — `Enum["RED"]`, `Enum("red")`, `list(Enum)`, `len(Enum)`, `@unique`, `auto()`, `isinstance` checks, everything.
|
|
467
465
|
|
|
466
|
+
A few deliberate differences from `enum.Enum` to keep in mind:
|
|
467
|
+
|
|
468
|
+
- `str(member)` returns the label, not `"ClassName.MEMBER"` (`repr()` shows
|
|
469
|
+
`<ClassName.MEMBER: value>`), and `member == value` compares by value.
|
|
470
|
+
- `serialize_by_name` is a reserved class attribute for Pydantic config — it
|
|
471
|
+
can't be used as a member name and must be a `bool`.
|
|
472
|
+
- Metadata keys that collide with real attributes (`name`, `value`, `label`,
|
|
473
|
+
`metadata`) are only reachable via `member.metadata`, not as attributes.
|
|
474
|
+
- Metadata declared on an alias is ignored — an alias shares the canonical
|
|
475
|
+
member's label and metadata.
|
|
476
|
+
|
|
468
477
|
## Changelog
|
|
469
478
|
|
|
470
479
|
See [CHANGELOG.md](CHANGELOG.md) for a full history of changes.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|

|
|
4
4
|

|
|
5
5
|

|
|
6
|
-

|
|
7
7
|
|
|
8
8
|
Python's `enum.Enum` is basic. `enumplus` adds display names, metadata, JSON
|
|
9
9
|
serialization, `choices()`, and value-based comparison — all with zero runtime
|
|
@@ -92,12 +92,12 @@ print("red" in Color) # True
|
|
|
92
92
|
|
|
93
93
|
### Display Names (label)
|
|
94
94
|
|
|
95
|
-
Every member gets a human-readable label, auto-generated from the member name or set explicitly via metadata.
|
|
95
|
+
Every member gets a human-readable label, auto-generated from the member name or set explicitly via metadata. Auto-generated labels replace underscores with spaces (`IN_PROGRESS` becomes `"In Progress"`).
|
|
96
96
|
|
|
97
97
|
```python
|
|
98
98
|
class Status(Enum):
|
|
99
|
-
PENDING = "pending"
|
|
100
|
-
IN_PROGRESS =
|
|
99
|
+
PENDING = "pending" # label: "Pending"
|
|
100
|
+
IN_PROGRESS = "in_progress" # label: "In Progress"
|
|
101
101
|
|
|
102
102
|
print(Status.PENDING.label) # "Pending"
|
|
103
103
|
print(Status.IN_PROGRESS.label) # "In Progress"
|
|
@@ -187,7 +187,7 @@ Color.keys() # ["RED", "GREEN"]
|
|
|
187
187
|
|
|
188
188
|
### filter()
|
|
189
189
|
|
|
190
|
-
Filter members by metadata key-value pairs (AND logic).
|
|
190
|
+
Filter members by metadata key-value pairs (AND logic). `label` is special: it matches against the evaluated label (including auto-generated and callable labels), not the raw metadata dict.
|
|
191
191
|
|
|
192
192
|
```python
|
|
193
193
|
class Color(Enum):
|
|
@@ -197,6 +197,7 @@ class Color(Enum):
|
|
|
197
197
|
Color.filter(category="warm") # [Color.RED]
|
|
198
198
|
Color.filter(hex="#FF0000", category="warm") # [Color.RED]
|
|
199
199
|
Color.filter() # [Color.RED, Color.GREEN]
|
|
200
|
+
Color.filter(label="Red") # [Color.RED]
|
|
200
201
|
```
|
|
201
202
|
|
|
202
203
|
### Comparison with values (==)
|
|
@@ -400,24 +401,21 @@ print(Color.labels()) # ["Rojo", "Verde"]
|
|
|
400
401
|
print(Color.choices()) # [("red", "Rojo"), ("green", "Verde")]
|
|
401
402
|
```
|
|
402
403
|
|
|
403
|
-
Callable labels work everywhere: `choices()`, `to_dict()`, `to_json()`, `labels()`, and `str()`.
|
|
404
|
+
Callable labels work everywhere: `choices()`, `to_dict()`, `to_json()`, `labels()`, `filter(label=...)`, and `str()`.
|
|
404
405
|
|
|
405
406
|
### Type hints in metadata
|
|
406
407
|
|
|
407
|
-
|
|
408
|
+
Metadata attributes are resolved at runtime through `__getattr__`, which
|
|
409
|
+
returns `Any`. Type checkers therefore accept `member.<key>` accesses as
|
|
410
|
+
`Any`, but cannot verify individual key names or value types.
|
|
408
411
|
|
|
409
412
|
```python
|
|
410
413
|
class Color(Enum):
|
|
411
414
|
RED = ("red", {"hex": "#FF0000"})
|
|
412
415
|
|
|
413
|
-
# Type checkers recognize .hex as a valid attribute
|
|
414
416
|
Color.RED.hex # inferred as Any via __getattr__
|
|
415
417
|
```
|
|
416
418
|
|
|
417
|
-
> **Note:** Type inference for metadata attributes depends on the type checker.
|
|
418
|
-
> The `@dataclass_transform()` decorator provides the structural hint, but
|
|
419
|
-
> runtime attribute access goes through `__getattr__`, which returns `Any`.
|
|
420
|
-
|
|
421
419
|
## Migration from stdlib
|
|
422
420
|
|
|
423
421
|
Just change one import:
|
|
@@ -432,6 +430,17 @@ from enumplus import Enum
|
|
|
432
430
|
|
|
433
431
|
All existing enum code continues to work — `Enum["RED"]`, `Enum("red")`, `list(Enum)`, `len(Enum)`, `@unique`, `auto()`, `isinstance` checks, everything.
|
|
434
432
|
|
|
433
|
+
A few deliberate differences from `enum.Enum` to keep in mind:
|
|
434
|
+
|
|
435
|
+
- `str(member)` returns the label, not `"ClassName.MEMBER"` (`repr()` shows
|
|
436
|
+
`<ClassName.MEMBER: value>`), and `member == value` compares by value.
|
|
437
|
+
- `serialize_by_name` is a reserved class attribute for Pydantic config — it
|
|
438
|
+
can't be used as a member name and must be a `bool`.
|
|
439
|
+
- Metadata keys that collide with real attributes (`name`, `value`, `label`,
|
|
440
|
+
`metadata`) are only reachable via `member.metadata`, not as attributes.
|
|
441
|
+
- Metadata declared on an alias is ignored — an alias shares the canonical
|
|
442
|
+
member's label and metadata.
|
|
443
|
+
|
|
435
444
|
## Changelog
|
|
436
445
|
|
|
437
446
|
See [CHANGELOG.md](CHANGELOG.md) for a full history of changes.
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
## Getting Help
|
|
4
4
|
|
|
5
5
|
- **Documentation**: Start with the [README](README.md) for usage examples and API reference.
|
|
6
|
-
- **Issues**: Search [existing issues](https://github.com/MathiasPaulenko/
|
|
7
|
-
- **Discussions**: Use [GitHub Discussions](https://github.com/MathiasPaulenko/
|
|
6
|
+
- **Issues**: Search [existing issues](https://github.com/MathiasPaulenko/enumplus/issues) to see if your question has already been answered.
|
|
7
|
+
- **Discussions**: Use [GitHub Discussions](https://github.com/MathiasPaulenko/enumplus/discussions) for questions, ideas, and general discussion.
|
|
8
8
|
|
|
9
9
|
## Reporting a Bug
|
|
10
10
|
|
|
11
|
-
Open a [bug report issue](https://github.com/MathiasPaulenko/
|
|
11
|
+
Open a [bug report issue](https://github.com/MathiasPaulenko/enumplus/issues/new?template=bug_report.md).
|
|
12
12
|
Include:
|
|
13
13
|
|
|
14
14
|
- Python version
|
|
@@ -18,7 +18,7 @@ Include:
|
|
|
18
18
|
|
|
19
19
|
## Requesting a Feature
|
|
20
20
|
|
|
21
|
-
Open a [feature request issue](https://github.com/MathiasPaulenko/
|
|
21
|
+
Open a [feature request issue](https://github.com/MathiasPaulenko/enumplus/issues/new?template=feature_request.md).
|
|
22
22
|
|
|
23
23
|
## Security Issues
|
|
24
24
|
|