Skip to content

Commit

Permalink
Deprecate Enum.from_value
Browse files Browse the repository at this point in the history
  • Loading branch information
loichuder committed Jul 11, 2024
1 parent e57c303 commit 0db75a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/silx/utils/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
__license__ = "MIT"
__date__ = "29/04/2019"


from silx.utils.deprecation import deprecated
import enum


class Enum(enum.Enum):
"""Enum with additional class methods."""

@classmethod
@deprecated(since_version="2.1.1", replacement="Enum(value)")
def from_value(cls, value):
"""Convert a value to corresponding Enum member
Expand Down
6 changes: 6 additions & 0 deletions src/silx/utils/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ class Success(Enum):
assert Success.from_value("B") == Success.B
with pytest.raises(ValueError):
Success.from_value(3)

# With built-in 'from_value'
assert Success(1) == Success.A
assert Success('B') == Success.B
with pytest.raises(ValueError):
Success(3)

0 comments on commit 0db75a3

Please sign in to comment.