IntEnum unsupported
I am trying enum examples from the mypy blog post introducing enums, but I can't get them to work.
My examples look like this:
from enum import IntEnum
Color = IntEnum('Color', ['red', 'blue', 'green'])
Color.red
This is the error for this example:
running build_ext
building 'enum_example' extension
gcc -pthread -B /home/ben/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/ben/anaconda3/lib/python3.6/site-packages/mypyc/lib-rt -I/home/ben/anaconda3/include/python3.6m -c build/__native.c -o build/temp.linux-x86_64-3.6/build/__native.o -O3 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable
build/__native.c: In function ‘CPyDef___top_level__’:
build/__native.c:183:29: error: ‘CPyType_Color’ undeclared (first use in this function); did you mean ‘PyType_Slot’?
cpy_r_r28 = (PyObject *)CPyType_Color;
^~~~~~~~~~~~~
PyType_Slot
build/__native.c:183:29: note: each undeclared identifier is reported only once for each function it appears in
build/__native.c: At top level:
cc1: error: unrecognized command line option ‘-Wno-unknown-warning-option’ [-Werror]
cc1: error: unrecognized command line option ‘-Wno-unused-command-line-argument’ [-Werror]
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1
I have the latest (released) version of mypy and a recent version of gcc
mypy==0.770
mypy-extensions==0.4.3
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
What I can compile and execute is this:
from enum import Enum, auto
class ExpEnum(Enum):
ONE = auto()
TWO = auto()
value = ExpEnum['ONE']
However, I want to use members like 'ONE-TWO', so I can't use the class style as far as I understand.
I'd like to use the functional API, because, ultimately, the functionality I want to get is:
Colors = Enum('colors', ['red', 'green', 'blue'])
assert Colors['red'] == 1
assert Colors.red == 1
# or even better: 0; I've noticed the 'start' option doesn't work
Using IntEnum with class-based syntax is also broken, but fails at runtime trying to look up int in the globals dict. I bet it is having weird interference from the plugin.
Also, in an Enum with int values, specifying Final on the class vars causes us to directly load the underlying int, which does not work
I was having trouble with this and namedtuples. Is it just the functional syntax that's supported in general?
new reports #896