Skip to content

Problem with enums #3969

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

Closed
hanpari opened this issue Sep 18, 2017 · 5 comments
Closed

Problem with enums #3969

hanpari opened this issue Sep 18, 2017 · 5 comments

Comments

@hanpari
Copy link

hanpari commented Sep 18, 2017

With that:

class Sample(Enum):
    one = 1
    two = 2


SampleTypeList = tp.List[Sample]
SampleList: SampleTypeList = [Sample.one, Sample.two] # Here is no problem
SampleListGenerated: SampleTypeList = list(Sample) # Here is problematic line
assert SampleList == SampleListGenerated, "It is same, but mypy says otherwise."
assert all(i is j for i, j in zip(SampleListGenerated,
                                  SampleList)), "The identical objects, indeed"

mypy complaints:

[mypy] error:Argument 1 to "list" has incompatible type Type[Sample]; expected Iterable[Sample]

From my points of view those lists are identical.

@JelleZijlstra
Copy link
Member

This works for me with this more minimal example:

import enum

class X(enum.Enum):
    a = 1

reveal_type(list(X))

The output is Revealed type is 'builtins.list[enum.Enum*]' with no other errors.

Are you using the latest version of mypy? We have made several fixes to enum in recent versions.

@hanpari
Copy link
Author

hanpari commented Sep 18, 2017

Thank you. Yes, I have the latest version of mypy. To make it clear: My example is working for you correctly with no complaint from mypy? It seems to me that mypy is not able to understand that Enum type can be unpack as a iterable.

mypy

@ilevkivskyi
Copy link
Member

The original example is confirmed on master, but it looks like this is another manifestation of #3210 (a duplicate?)

@JelleZijlstra note that the revealed type shows builtins.list[enum.Enum*], while it should be builtins.list[__main__.Sample*].

@elazarg
Copy link
Contributor

elazarg commented Sep 20, 2017

I'm pretty sure it's a duplicate.

@gvanrossum
Copy link
Member

Agreed.

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

5 participants