Skip to content

Commit defd540

Browse files
author
Guido van Rossum
committed
Add more test cases
1 parent b44cbf5 commit defd540

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test-data/unit/check-classes.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,3 +3157,37 @@ class M(type):
31573157
x = 5
31583158
class A(with_metaclass(M)): pass
31593159
reveal_type(type(A).x) # E: Revealed type is 'builtins.int'
3160+
3161+
[case testSixWithMetaclassAndBase]
3162+
import six
3163+
class M(type):
3164+
x = 5
3165+
class A:
3166+
def foo(self): pass
3167+
class B:
3168+
def bar(self): pass
3169+
class C1(six.with_metaclass(M, A)): pass
3170+
class C2(six.with_metaclass(M, A, B)): pass
3171+
reveal_type(type(C1).x) # E: Revealed type is 'builtins.int'
3172+
reveal_type(type(C2).x) # E: Revealed type is 'builtins.int'
3173+
C1().foo()
3174+
C1().bar() # E: "C1" has no attribute "bar"
3175+
C2().foo()
3176+
C2().bar()
3177+
C2().baz() # E: "C2" has no attribute "baz"
3178+
3179+
[case testSixWithMetaclassErrors]
3180+
import six
3181+
class M(type): pass
3182+
class A(object): pass
3183+
class C1(six.with_metaclass(M), object): pass # E: Invalid base class
3184+
class C2(C1, six.with_metaclass(M)): pass # E: Invalid base class
3185+
class C3(six.with_metaclass(A)): pass # E: Metaclasses not inheriting from 'type' are not supported
3186+
class C4(six.with_metaclass(M), metaclass=M): pass # E: Invalid base class
3187+
3188+
[case testSixWithMetaclassErrors_python2-skip]
3189+
# No error here yet
3190+
import six
3191+
class M(type): pass
3192+
class C4(six.with_metaclass(M)):
3193+
__metaclass__ = M

0 commit comments

Comments
 (0)