From: W. Trevor King Date: Thu, 17 Jul 2014 18:12:36 +0000 (-0700) Subject: constant: Avoid non-integer values in _Enum X-Git-Tag: 0.8~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=56aa22110c08eed90512dbce6323f46c2166aeba;p=pycomedi.git constant: Avoid non-integer values in _Enum When my lowercase names collide (e.g. for COMEDI_TO_PHYSICAL and comedi_to_physical), we want to add the integer value to the enum, not the function value. This avoids: >>> from pycomedi.device import Device Traceback (most recent call last): File "", line 1, in File "instruction.pxd", line 22, in init pycomedi.device (pycomedi/device.c:4532) File "instruction.pyx", line 25, in init pycomedi.instruction (pycomedi/instruction.c:2427) File "chanspec.pyx", line 20, in init pycomedi.chanspec (pycomedi/chanspec.c:2571) File "constant.pyx", line 469, in init pycomedi.constant (pycomedi/constant.c:10017) File "constant.pyx", line 244, in pycomedi.constant._Enum.__init__ (pycomedi/constant.c:3804) File "constant.pyx", line 260, in pycomedi.constant._Enum._add_item (pycomedi/constant.c:4305) TypeError: unorderable types: builtin_function_or_method() < int() I'm not sure how I haven't bumped into this before. Perhaps Cython 0.19.1 has stronger type-checking for its comparison operaters than my old 0.17.4. --- diff --git a/pycomedi/constant.pyx b/pycomedi/constant.pyx index 41c669c..f3fb50a 100644 --- a/pycomedi/constant.pyx +++ b/pycomedi/constant.pyx @@ -257,6 +257,8 @@ class _Enum (list): def _add_item(self, attr, item_name): item_value = getattr(_comedi, attr) + if not isinstance(item_value, int): + return # item_name collided with another object, skip this non-int if item_value < 0: _LOG.debug('big value for {0:s}: {1:d} ({1:b}) converted to {2:d} ({2:b})'.format( attr, item_value, (1<<32) + item_value))