Skip to content

Commit 85fd3f6

Browse files
committed
more tests
1 parent ed7171d commit 85fd3f6

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def analyze_base_classes(self, defn: ClassDef) -> None:
10891089
if defn.info.is_enum and defn.type_vars:
10901090
self.fail("Enum class cannot be generic", defn)
10911091

1092-
def update_metaclass(self, defn: ClassDef):
1092+
def update_metaclass(self, defn: ClassDef) -> None:
10931093
"""Lookup for special metaclass declarations, and update defn fields accordingly.
10941094
10951095
* __metaclass__ attribute in Python 2

test-data/unit/check-classes.test

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,27 +3525,31 @@ class M(type):
35253525
x = 5
35263526

35273527
[case testSixMetaclassAndBase]
3528+
from typing import Iterable, Iterator
35283529
import six
3529-
class M(type):
3530+
class M(type, Iterable[int]):
35303531
x = 5
3532+
def __iter__(self) -> Iterator[int]: ...
35313533
class A:
35323534
def foo(self): pass
35333535
class B:
35343536
def bar(self): pass
35353537
class C1(six.with_metaclass(M, A)): pass
3536-
class C2(six.with_metaclass(M, A, B)): pass
35373538
@six.add_metaclass(M)
35383539
class D1(A): pass
3540+
class C2(six.with_metaclass(M, A, B)): pass
35393541
@six.add_metaclass(M)
35403542
class D2(A, B): pass
35413543
reveal_type(type(C1).x) # E: Revealed type is 'builtins.int'
3542-
reveal_type(type(C2).x) # E: Revealed type is 'builtins.int'
35433544
reveal_type(type(D1).x) # E: Revealed type is 'builtins.int'
3545+
reveal_type(type(C2).x) # E: Revealed type is 'builtins.int'
35443546
reveal_type(type(D2).x) # E: Revealed type is 'builtins.int'
35453547
C1().foo()
35463548
D1().foo()
35473549
C1().bar() # E: "C1" has no attribute "bar"
35483550
D1().bar() # E: "D1" has no attribute "bar"
3551+
for x in C1: reveal_type(x) # E: Revealed type is 'builtins.int*'
3552+
for x in C2: reveal_type(x) # E: Revealed type is 'builtins.int*'
35493553
C2().foo()
35503554
D2().foo()
35513555
C2().bar()
@@ -3591,6 +3595,21 @@ class C5(six.with_metaclass(f())): pass # E: Dynamic metaclass not supported fo
35913595
@six.add_metaclass(f()) # E: Dynamic metaclass not supported for 'D5'
35923596
class D5: pass
35933597

3598+
@six.add_metaclass(M) # E: Multiple metaclass definitions
3599+
class CD(six.with_metaclass(M)): pass
3600+
3601+
def q(t):
3602+
class E(metaclass=t): pass
3603+
class F(six.with_metaclass(t)): pass
3604+
@six.add_metaclass(t)
3605+
class G: pass
3606+
3607+
class M1(type): pass
3608+
class Q1(metaclass=M1): pass
3609+
@six.add_metaclass(M) # E: Inconsistent metaclass structure for 'CQA'
3610+
class CQA(Q1): pass
3611+
class CQW(six.with_metaclass(M, Q1)): pass # E: Inconsistent metaclass structure for 'CQW'
3612+
35943613
[case testSixMetaclassErrors_python2]
35953614
# flags: --python-version 2.7
35963615
import six

0 commit comments

Comments
 (0)