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

Enum.value treated as Enum #3546

Closed
matkuki opened this issue Jun 14, 2017 · 2 comments
Closed

Enum.value treated as Enum #3546

matkuki opened this issue Jun 14, 2017 · 2 comments

Comments

@matkuki
Copy link

matkuki commented Jun 14, 2017

Hi guys,

I couldn't find a similar issue, so apologies if there is a similar issue already open or closed.

Why doesn't this example show an error for wrong argument type in the last line:

import enum

class TempEnum(enum.Enum):
    one = 1
    two = 2

def test_func(arg: TempEnum) -> None:
    print(arg)
 
test_func(TempEnum.one.value) # No error ?

Shouldn't this be an error as .value is an int?
I'm using Python 3.5 and mypy 0.511.

Matic

@emmatyping
Copy link
Collaborator

emmatyping commented Jun 15, 2017

In the typing stub https://github.com/python/typeshed/blob/master/stdlib/3.4/enum.pyi#L25
Enum.value has type Any. MyPy can't narrow the type here. I believe there is thought on better support for Enum through plugins.

@matkuki
Copy link
Author

matkuki commented Jun 15, 2017

@ethanhs
Thanks for the details. It just feels counter-intuitive. Hope it gets upgraded.

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

No branches or pull requests

2 participants