Skip to content

Commit

Permalink
Support additional superclass (issue python#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
elazarg committed Sep 3, 2016
1 parent f5683ca commit c50ba9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def visit_tuple_type(self, left: TupleType) -> bool:
is_named_instance(right, 'typing.Reversible')):
iter_type = right.args[0]
return all(is_subtype(li, iter_type) for li in left.items)
if is_subtype(left.fallback, right, self.check_type_parameter):
return True
return False
elif isinstance(right, TupleType):
if len(left.items) != len(right.items):
Expand Down
22 changes: 21 additions & 1 deletion test-data/unit/check-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,24 @@ reveal_type(X._field_types) # E: Revealed type is 'builtins.dict[builtins.str,
x = None # type: X
reveal_type(x._field_types) # E: Revealed type is 'builtins.dict[builtins.str, Any]'

[builtins fixtures/dict.pyi]
[builtins fixtures/dict.pyi]

[case testNamedTupleAndOtherSuperclass]
from typing import NamedTuple

class A: pass
def f(x: A) -> None: pass

class B(NamedTuple('B', []), A): pass
f(B())
x = None # type: A
x = B()

# Sanity check: fail if baseclass does not match
class C: pass
def g(x: C) -> None: pass
class D(NamedTuple('D', []), A): pass

g(D()) # E: Argument 1 to "g" has incompatible type "D"; expected "C"
y = None # type: C
y = D() # E: Incompatible types in assignment (expression has type "D", variable has type "C")

0 comments on commit c50ba9d

Please sign in to comment.