]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91578: improved error message when trying to instantiate an abstract class with...
authorravi140222 <100869741+ravi140222@users.noreply.github.com>
Thu, 12 May 2022 15:26:11 +0000 (20:56 +0530)
committerGitHub <noreply@github.com>
Thu, 12 May 2022 15:26:11 +0000 (11:26 -0400)
Lib/test/test_abc.py
Lib/test/test_dataclasses.py
Misc/NEWS.d/next/Core and Builtins/2022-04-15-22-12-53.gh-issue-91578.rDOtyK.rst [new file with mode: 0644]
Objects/typeobject.c

index 1e7a0351db489d13c9577b42229b6aa239bcfbf6..a083236fb0fc44bab7a970a0e20e16dde2f28be5 100644 (file)
@@ -154,7 +154,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
                 @abc.abstractmethod
                 def method_one(self):
                     pass
-            msg = r"class C with abstract method method_one"
+            msg = r"class C without an implementation for abstract method method_one"
             self.assertRaisesRegex(TypeError, msg, C)
 
         def test_object_new_with_many_abstractmethods(self):
@@ -165,7 +165,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
                 @abc.abstractmethod
                 def method_two(self):
                     pass
-            msg = r"class C with abstract methods method_one, method_two"
+            msg = r"class C without an implementation for abstract methods method_one, method_two"
             self.assertRaisesRegex(TypeError, msg, C)
 
         def test_abstractmethod_integration(self):
@@ -535,7 +535,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
             A.foo = updated_foo
             abc.update_abstractmethods(A)
             self.assertEqual(A.__abstractmethods__, {'foo', 'bar'})
-            msg = "class A with abstract methods bar, foo"
+            msg = "class A without an implementation for abstract methods bar, foo"
             self.assertRaisesRegex(TypeError, msg, A)
 
         def test_update_implementation(self):
@@ -547,7 +547,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
             class B(A):
                 pass
 
-            msg = "class B with abstract method foo"
+            msg = "class B without an implementation for abstract method foo"
             self.assertRaisesRegex(TypeError, msg, B)
             self.assertEqual(B.__abstractmethods__, {'foo'})
 
@@ -605,7 +605,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
 
             abc.update_abstractmethods(B)
 
-            msg = "class B with abstract method foo"
+            msg = "class B without an implementation for abstract method foo"
             self.assertRaisesRegex(TypeError, msg, B)
 
         def test_update_layered_implementation(self):
@@ -627,7 +627,7 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
 
             abc.update_abstractmethods(C)
 
-            msg = "class C with abstract method foo"
+            msg = "class C without an implementation for abstract method foo"
             self.assertRaisesRegex(TypeError, msg, C)
 
         def test_update_multi_inheritance(self):
index 6a36da104ac89ad11a904e90d6c988c3c9ed1280..cf29cd07516f0d3f6f97296d46bdaf5fca871768 100644 (file)
@@ -3762,7 +3762,7 @@ class TestAbstract(unittest.TestCase):
             day: 'int'
 
         self.assertTrue(inspect.isabstract(Date))
-        msg = 'class Date with abstract method foo'
+        msg = 'class Date without an implementation for abstract method foo'
         self.assertRaisesRegex(TypeError, msg, Date)
 
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-04-15-22-12-53.gh-issue-91578.rDOtyK.rst b/Misc/NEWS.d/next/Core and Builtins/2022-04-15-22-12-53.gh-issue-91578.rDOtyK.rst
new file mode 100644 (file)
index 0000000..4dc738a
--- /dev/null
@@ -0,0 +1 @@
+Updates the error message for abstract class.
index 1bcfd9a9c52bcd60f605479fc140664e3d3c7539..1daf2b8d3b0ff863e93f0f8fb611bcb71d094142 100644 (file)
@@ -4559,7 +4559,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
         PyErr_Format(PyExc_TypeError,
                      "Can't instantiate abstract class %s "
-                     "with abstract method%s %U",
+                     "without an implementation for abstract method%s %U",
                      type->tp_name,
                      method_count > 1 ? "s" : "",
                      joined);