[pypy-commit] pypy py3.6: Add parentheses to an error message: "__prepare__() must return a mapping..."

paugier pypy.commits at gmail.com
Fri Sep 6 06:36:16 EDT 2019


Author: paugier <pierre.augier at univ-grenoble-alpes.fr>
Branch: py3.6
Changeset: r97385:a18f99a9128a
Date: 2019-09-06 12:30 +0200
http://bitbucket.org/pypy/pypy/changeset/a18f99a9128a/

Log:	Add parentheses to an error message: "__prepare__() must return a
	mapping..."

diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -133,11 +133,11 @@
     if not space.ismapping_w(w_namespace):
         if isclass:
             raise oefmt(space.w_TypeError,
-                "%N.__prepare__ must return a mapping, not %T",
+                "%N.__prepare__() must return a mapping, not %T",
                 w_meta, w_namespace)
         else:
             raise oefmt(space.w_TypeError,
-                "<metaclass>.__prepare__ must return a mapping, not %T",
+                "<metaclass>.__prepare__() must return a mapping, not %T",
                 w_namespace)
 
     code = w_func.getcode()
diff --git a/pypy/module/__builtin__/test/apptest_compile.py b/pypy/module/__builtin__/test/apptest_compile.py
--- a/pypy/module/__builtin__/test/apptest_compile.py
+++ b/pypy/module/__builtin__/test/apptest_compile.py
@@ -179,3 +179,20 @@
         assert 'module_doc' not in marshalled
         assert 'func_doc' not in marshalled
         assert 'class_doc' not in marshalled
+
+def test_build_class():
+    """Test error message bad __prepare__"""
+
+    class BadMeta(type):
+        @classmethod
+        def __prepare__(*args):
+            return None
+
+    def func():
+        class Foo(metaclass=BadMeta):
+            pass
+
+    excinfo = raises(TypeError, func)
+    assert str(excinfo.value) == (
+        r"BadMeta.__prepare__() must return a mapping, not NoneType"
+    )


More information about the pypy-commit mailing list