PyCharm 2022 treat IntEnum.value as a function instead a int, which resulted in a false warnings

Answered

The Code is like:

class EnumClass(IntEnum):
Member1 = 1
Member2 = 2

# The code below works well in Python, and previous versions of PyCharm also didn't treat it as a warning.
# But in PyCharm 2022, there will be a warning like: Expected type 'int', got '() -> int' instead
need_int_var: int = EnumClass.Member1.value

# I can't just close the inspection "Incorrect type", which may cause bigger problems.
# But how can I fix this?
2
1 comment

Unfortunately, it's a known regression https://youtrack.jetbrains.com/issue/PY-55734/Python-Enum-type-hinting-is-broken, please vote for it and feel free to comment.

As a temporary workaround, you can downgrade to 2022.1.4 https://www.jetbrains.com/pycharm/download/other.html

I'm sorry for the inconvenience.

0

Please sign in to leave a comment.