Skip to content

Support NamedTuple-derived Enum #2407

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

Merged
merged 2 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def visit_instance(self, left: Instance) -> bool:
if left.type.fallback_to_any:
return True
right = self.right
if isinstance(right, TupleType) and right.fallback.type.is_enum:
return is_subtype(left, right.fallback)
if isinstance(right, Instance):
if left.type._promote and is_subtype(left.type._promote,
self.right,
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/pythoneval-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,17 @@ takes_int(SomeExtIntEnum.x)
def takes_some_ext_int_enum(s: SomeExtIntEnum):
pass
takes_some_ext_int_enum(SomeExtIntEnum.x)


[case testNamedTupleEnum]
from typing import NamedTuple
from enum import Enum

N = NamedTuple('N', [('bar', int)])

class E(N, Enum):
X = N(1)

def f(x: E) -> None: pass

f(E.X)