Author: Armin Rigo <[email protected]>
Branch:
Changeset: r72703:51ad4dce5ecd
Date: 2014-08-06 17:26 +0200
http://bitbucket.org/pypy/pypy/changeset/51ad4dce5ecd/
Log: Crash translation if we're trying to use mixin classes in ways that
are not supported
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -419,6 +419,10 @@
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)
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -2536,6 +2536,22 @@
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):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit