Pylint: issue with enum.Enum.value (@DynamicClassAttribue vs @property)

Created on 16 Jul 2018  路  5Comments  路  Source: PyCQA/pylint

Steps to reproduce

from enum import Enum

class Color(Enum):
    red = 1
    green = 2
    blue = 3

    def __lt__(self, other):
        return self.value < other.value
$ pylint -d C testcase_enum.py
************* Module testcase_enum
testcase_enum.py:9:15: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)

------------------------------------------------------------------
Your code has been rated at 8.57/10 (previous run: 8.57/10, +0.00)

In python 3.4.2 (debian jessie's python), value is defined like so:

    @DynamicClassAttribute
    def value(self):
        """The value of the Enum member."""
        return self._value_

@DynamicClassAttribue is supposed to be like @property but not quite, according to the docstring. I didn't get too much into it.

pylint --version output

$ pylint --version
pylint 2.0.0
astroid 2.0.0.dev4
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1]
astroid bug

Most helpful comment

Thanks for the report! This is a false positive that happens because we can't infer properly the value attribute, will need an update in astroid.

All 5 comments

Thanks for the report! This is a false positive that happens because we can't infer properly the value attribute, will need an update in astroid.

appears to be fixed in recent version

The bug unfortunately is still present with the latest release.

As for now, with the pylint v2.3.1 / astroid v2.2.5 the problem is still actual.

However, for those who lurk for a workaround, here it is:

value = int(self.value)
if value < other.value:
...

With that pylint becomes happy.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pylint-bot picture pylint-bot  路  3Comments

glmdgrielson picture glmdgrielson  路  3Comments

thanatos picture thanatos  路  3Comments

TBoshoven picture TBoshoven  路  3Comments

DevynCJohnson picture DevynCJohnson  路  3Comments