New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use an enum type as type argument #2658

Open
DanielHerding opened this Issue Oct 15, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@DanielHerding

DanielHerding commented Oct 15, 2018

When a function argument has a type hint ": type", I cannot pass an enum type after cythonizing.

Example module test.py:

from enum import IntEnum
from enum import EnumMeta

class MyEnumType(IntEnum):
    FOO = 0
    BAR = 1

def function1(t: type):
    print(t, type(t))

print(isinstance(MyEnumType.FOO, MyEnumType))
print(isinstance(MyEnumType, EnumMeta))
print(isinstance(MyEnumType, type))
print(issubclass(EnumMeta, type))
function1(str)
function1(MyEnumType)

Output before cythonizing:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
>>> import test1
True
True
True
True
<class 'str'> <class 'type'>
<enum 'MyEnumType'> <class 'enum.EnumMeta'>

Output after cythonizing:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import test1
True
True
True
True
(<class 'str'>, <class 'type'>)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "otx\test1.py", line 16, in init test1
TypeError: Argument 't' has incorrect type (expected type, got EnumMeta)

Used compiler directive: "always_allow_keywords": True
Used Cython version 0.28.5 on Windows 7

Workaround: Remove the type hint from the argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment