Skip to content

Commit 89f1a42

Browse files
committed
Deprecate Enum class
1 parent a5eac72 commit 89f1a42

File tree

9 files changed

+93
-83
lines changed

9 files changed

+93
-83
lines changed

src/silx/gui/dialog/ColormapDialog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
from silx.math.histogram import Histogramnd
8787
from silx.gui.plot.items.roi import RectangleROI
8888
from silx.gui.plot.tools.roi import RegionOfInterestManager
89-
from silx.utils.enum import Enum as _Enum
89+
from silx.utils._enum import Enum as _Enum
9090

9191
_logger = logging.getLogger(__name__)
9292

src/silx/gui/plot/ImageView.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
from .Profile import ProfileToolBar
5959
from ...utils.proxy import docstring
6060
from ...utils.deprecation import deprecated
61-
from ...utils.enum import Enum
61+
from ...utils._enum import Enum
6262
from .tools.RadarView import RadarView
6363
from .utils.axis import SyncAxes
6464
from ..utils import blockSignals

src/silx/gui/plot/StatsWidget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import numpy
3838
import enum
3939
from silx.utils.proxy import docstring
40-
from silx.utils.enum import Enum as _Enum
40+
from silx.utils._enum import Enum as _Enum
4141
from silx.gui import qt
4242
from silx.gui import icons
4343
from silx.gui.plot import stats as statsmdl

src/silx/gui/plot/items/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import numpy
4242

4343
from ....utils.proxy import docstring
44-
from ....utils.enum import Enum as _Enum
44+
from ....utils._enum import Enum as _Enum
4545
from ....math.combo import min_max
4646
from ... import qt
4747
from ... import colors

src/silx/gui/plot/items/image_aggregated.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import numpy
3737

38-
from ....utils.enum import Enum as _Enum
38+
from ....utils._enum import Enum as _Enum
3939
from ....utils.proxy import docstring
4040
from .axis import Axis
4141
from .core import ItemChangedType

src/silx/gui/plot3d/Plot3DWidget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from silx.gui.colors import rgba
3636
from . import actions
3737

38-
from ...utils.enum import Enum as _Enum
38+
from ...utils._enum import Enum as _Enum
3939
from ..utils.image import convertArrayToQImage
4040

4141
from .. import _glutils as glu

src/silx/utils/_enum.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# /*##########################################################################
2+
#
3+
# Copyright (c) 2019 European Synchrotron Radiation Facility
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
#
23+
# ###########################################################################*/
24+
"""An :class:`.Enum` class with additional features."""
25+
26+
__authors__ = ["T. Vincent"]
27+
__license__ = "MIT"
28+
__date__ = "29/04/2019"
29+
30+
31+
import enum
32+
33+
34+
35+
class Enum(enum.Enum):
36+
"""Enum with additional class methods."""
37+
38+
@classmethod
39+
def from_value(cls, value):
40+
"""Convert a value to corresponding Enum member
41+
42+
:param value: The value to compare to Enum members
43+
If it is already a member of Enum, it is returned directly.
44+
:return: The corresponding enum member
45+
:rtype: Enum
46+
:raise ValueError: In case the conversion is not possible
47+
"""
48+
if isinstance(value, cls):
49+
return value
50+
for member in cls:
51+
if value == member.value:
52+
return member
53+
raise ValueError("Cannot convert: %s" % value)
54+
55+
@classmethod
56+
def members(cls):
57+
"""Returns a tuple of all members.
58+
59+
:rtype: Tuple[Enum]
60+
"""
61+
return tuple(member for member in cls)
62+
63+
@classmethod
64+
def names(cls):
65+
"""Returns a tuple of all member names.
66+
67+
:rtype: Tuple[str]
68+
"""
69+
return tuple(member.name for member in cls)
70+
71+
@classmethod
72+
def values(cls):
73+
"""Returns a tuple of all member values.
74+
75+
:rtype: Tuple
76+
"""
77+
return tuple(member.value for member in cls)

src/silx/utils/enum.py

+9-76
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,9 @@
1-
# /*##########################################################################
2-
#
3-
# Copyright (c) 2019 European Synchrotron Radiation Facility
4-
#
5-
# Permission is hereby granted, free of charge, to any person obtaining a copy
6-
# of this software and associated documentation files (the "Software"), to deal
7-
# in the Software without restriction, including without limitation the rights
8-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
# copies of the Software, and to permit persons to whom the Software is
10-
# furnished to do so, subject to the following conditions:
11-
#
12-
# The above copyright notice and this permission notice shall be included in
13-
# all copies or substantial portions of the Software.
14-
#
15-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
# THE SOFTWARE.
22-
#
23-
# ###########################################################################*/
24-
"""An :class:`.Enum` class with additional features."""
25-
26-
__authors__ = ["T. Vincent"]
27-
__license__ = "MIT"
28-
__date__ = "29/04/2019"
29-
30-
31-
import enum
32-
33-
34-
class Enum(enum.Enum):
35-
"""Enum with additional class methods."""
36-
37-
@classmethod
38-
def from_value(cls, value):
39-
"""Convert a value to corresponding Enum member
40-
41-
:param value: The value to compare to Enum members
42-
If it is already a member of Enum, it is returned directly.
43-
:return: The corresponding enum member
44-
:rtype: Enum
45-
:raise ValueError: In case the conversion is not possible
46-
"""
47-
if isinstance(value, cls):
48-
return value
49-
for member in cls:
50-
if value == member.value:
51-
return member
52-
raise ValueError("Cannot convert: %s" % value)
53-
54-
@classmethod
55-
def members(cls):
56-
"""Returns a tuple of all members.
57-
58-
:rtype: Tuple[Enum]
59-
"""
60-
return tuple(member for member in cls)
61-
62-
@classmethod
63-
def names(cls):
64-
"""Returns a tuple of all member names.
65-
66-
:rtype: Tuple[str]
67-
"""
68-
return tuple(member.name for member in cls)
69-
70-
@classmethod
71-
def values(cls):
72-
"""Returns a tuple of all member values.
73-
74-
:rtype: Tuple
75-
"""
76-
return tuple(member.value for member in cls)
1+
from ._enum import *
2+
from silx.utils.deprecation import deprecated_warning
3+
4+
deprecated_warning(
5+
"Class",
6+
"silx.utils.enum.Enum",
7+
since_version="2.1.1",
8+
replacement="Python built-in Enum class",
9+
)

src/silx/utils/test/test_enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
import pytest
32-
from silx.utils.enum import Enum
32+
from silx.utils._enum import Enum
3333

3434

3535
def test_enum_methods():

0 commit comments

Comments
 (0)