[python-arrayfire] 230/250: Ensure that the types of the enums values are correct

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit cf38ac38b838d925eb533ce57d588c25380bacec
Author: Filipe Maia <filipe.c.maia at gmail.com>
Date:   Thu Mar 3 00:20:55 2016 +0100

    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.
---
 arrayfire/library.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arrayfire/library.py b/arrayfire/library.py
index 4854d93..dc77eae 100644
--- a/arrayfire/library.py
+++ b/arrayfire/library.py
@@ -19,8 +19,15 @@ try:
     def _Enum_Type(v):
         return v
 except:
+    class _MetaEnum(type):
+        def __init__(cls, name, bases, attrs):
+            for attrname, attrvalue in attrs.iteritems():
+                if name != '_Enum' and isinstance(attrvalue, _Enum_Type):
+                    attrvalue.__class__ = cls
+                    attrs[attrname] = attrvalue
+
     class _Enum(object):
-        pass
+        __metaclass__ = _MetaEnum
 
     class _Enum_Type(object):
         def __init__(self, v):
@@ -31,7 +38,7 @@ class ERR(_Enum):
     Error values. For internal use only.
     """
 
-    NONE            =   _Enum_Type(0)
+    NONE            = _Enum_Type(0)
 
     #100-199 Errors in environment
     NO_MEM         = _Enum_Type(101)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list