Commit 6ddffd07 authored by Armin Rigo's avatar Armin Rigo

Crash translation if we're trying to use mixin classes in ways that

are not supported
parent 09101bbe
......@@ -419,6 +419,10 @@ class ClassDesc(Desc):
base = object
baselist = list(cls.__bases__)
if cls.__dict__.get('_mixin_', False):
raise Exception("cannot use directly the class %r because it"
" is a _mixin_" % (cls,))
# special case: skip BaseException in Python 2.5, and pretend
# that all exceptions ultimately inherit from Exception instead
# of BaseException (XXX hack)
......
......@@ -2536,6 +2536,22 @@ class TestAnnotateTestCase:
s = a.build_types(f, [])
assert s.const == 2
def test_cannot_use_directly_mixin(self):
class A(object):
_mixin_ = True
#
def f():
return A()
a = self.RPythonAnnotator()
py.test.raises(Exception, a.build_types, f, [])
#
class B(object):
pass
x = B()
def g():
return isinstance(x, A)
py.test.raises(Exception, a.build_types, g, [])
def test_import_from_mixin(self):
class M(object):
def f(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment