Skip to content

Commit cf38ac3

Browse files
committed
Ensure that the types of the enums values are correct
When the enum package is not available it's necessary to change the type of the _Enum_Type attributes inside a class derived from _Enum to match the type of the containing class (e.g. set the type of NONE inside the class ERR to ERR). Otherwise the behaviour with or without the enum package would be different.
1 parent 5b5a25f commit cf38ac3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arrayfire/library.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
def _Enum_Type(v):
2020
return v
2121
except:
22+
class _MetaEnum(type):
23+
def __init__(cls, name, bases, attrs):
24+
for attrname, attrvalue in attrs.iteritems():
25+
if name != '_Enum' and isinstance(attrvalue, _Enum_Type):
26+
attrvalue.__class__ = cls
27+
attrs[attrname] = attrvalue
28+
2229
class _Enum(object):
23-
pass
30+
__metaclass__ = _MetaEnum
2431

2532
class _Enum_Type(object):
2633
def __init__(self, v):
@@ -31,7 +38,7 @@ class ERR(_Enum):
3138
Error values. For internal use only.
3239
"""
3340

34-
NONE = _Enum_Type(0)
41+
NONE = _Enum_Type(0)
3542

3643
#100-199 Errors in environment
3744
NO_MEM = _Enum_Type(101)

0 commit comments

Comments
 (0)