Skip to content

Commit

Permalink
Support NamedTuple-derived Enum (#2407)
Browse files Browse the repository at this point in the history
Fix #1745.
  • Loading branch information
elazarg authored and gvanrossum committed Nov 7, 2016
1 parent baa4628 commit bf9cb22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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)

0 comments on commit bf9cb22

Please sign in to comment.