Skip to content
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

Bug: Functional Enum API Unexpected arguments to Enum() #9079

Closed
xylix opened this issue Jul 1, 2020 · 5 comments · Fixed by #9123
Closed

Bug: Functional Enum API Unexpected arguments to Enum() #9079

xylix opened this issue Jul 1, 2020 · 5 comments · Fixed by #9123

Comments

@xylix
Copy link

xylix commented Jul 1, 2020

I get error

enum-repro.py:3: error: Unexpected arguments to Enum()
Found 1 error in 1 file (checked 1 source file)

When mypy checking for example

from enum import Enum

enum_name = Enum(
    value="enum_name",
    names={
        "a": 1,
        "b": 2
    }
)
print(enum_name)

I'm using mypy 0.782 and Python 3.8.3. Also tried latest master (0.790+dev.eae1860bef0a6fe06753459bf97633a41e789ed7)

Since this is valid python3 syntax, I would expect mypy to at least let it through, maybe with a warning about dynamic types being impossible to infer at static typecheck time.

For my actual use case, I could try using the class EnumName(Enum)): form but It doesn't fully support my use case, because I would like to use names containing spaces and special symbols.

@JelleZijlstra
Copy link
Member

This should work if you use positional instead of keyword arguments. For example, the mypy test suite contains a E = Enum('E', {'foo': 1, 'bar': 2}). It wouldn't be hard to support keyword arguments (feel free to submit a PR!), but we just haven't taken the time to implement it.

@xylix
Copy link
Author

xylix commented Jul 2, 2020

Okay great, I understand that specifically not being implemented. The unnamed arguments will do as a workaround for now, solves my use case.

@LiuYuHui
Copy link
Contributor

LiuYuHui commented Jul 7, 2020

hi, @JukkaL @JelleZijlstra I want to fix this issue, could you please give some suggestions about where to start?

@JelleZijlstra
Copy link
Member

@LiuYuHui you can add new test cases to the check-enum.test file. The implementation would probably go in the parse_enum_call_args method in semanal_enum.py.

@charnugagoo
Copy link

I am having the same issue.

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

Successfully merging a pull request may close this issue.

5 participants