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

Dynamic Enum instantiation #9703

Closed
firebirdberlin opened this issue Nov 5, 2020 · 1 comment
Closed

Dynamic Enum instantiation #9703

firebirdberlin opened this issue Nov 5, 2020 · 1 comment
Labels
bug mypy got something wrong

Comments

@firebirdberlin
Copy link

Dynamically instantiating an Enum raises an error.

To Reproduce

di = {f: f.upper() for f in ["n1", "n2"]}
ArticleEnum = Enum("ArticleEnum", di)

The error message is:
article.py:197: error: Enum() expects a string, tuple, list or dict literal as the second argument

Expected Behavior
If I change the code snippet to hard-code the dictionary, no error occurs. This is what I expect the upper example to behave as well.

di = {f: f.upper() for f in ["n1", "n2"]}
ArticleEnum = Enum("ArticleEnum", {"n1": "N1", "n2": "N2"})

Your Environment
mypy 0.790 in a virtual env (peenv) on MacOS, mypy is invoked on the shell without any special arguments and no configuration

$ mypy src/

I am using Python 3.9.0.

@firebirdberlin firebirdberlin added the bug mypy got something wrong label Nov 5, 2020
@MestreLion
Copy link
Contributor

Duplicate of #5317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants