]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44089: Allow subclassing of ``csv.Error`` (GH-26008)
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Wed, 12 May 2021 13:47:11 +0000 (21:47 +0800)
committerGitHub <noreply@github.com>
Wed, 12 May 2021 13:47:11 +0000 (06:47 -0700)
* fix subclass error

* Update 2021-05-09-22-52-34.bpo-44089.IoANsN.rst

Lib/test/test_csv.py
Misc/NEWS.d/next/Library/2021-05-09-22-52-34.bpo-44089.IoANsN.rst [new file with mode: 0644]
Modules/_csv.c

index 2411a91110dd43806d6f73cae168f8448d9a1760..a1e050acd2a0c6ddc41e956ae0dea2f19485dd5c 100644 (file)
@@ -1237,6 +1237,9 @@ class MiscTestCase(unittest.TestCase):
         extra = {'__doc__', '__version__'}
         support.check__all__(self, csv, ('csv', '_csv'), extra=extra)
 
+    def test_subclassable(self):
+        # issue 44089
+        class Foo(csv.Error): ...
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2021-05-09-22-52-34.bpo-44089.IoANsN.rst b/Misc/NEWS.d/next/Library/2021-05-09-22-52-34.bpo-44089.IoANsN.rst
new file mode 100644 (file)
index 0000000..b9bd963
--- /dev/null
@@ -0,0 +1,2 @@
+Allow subclassing ``csv.Error`` in 3.10 (it was allowed in 3.9 and earlier but
+was disallowed in early versions of 3.10).
index cade1ca9d47f06aed074a27e2e8cf2d99b3c66f4..bdb67fdb4876fe0b1ce601ddbc2eb092ce0c787a 100644 (file)
@@ -1515,7 +1515,7 @@ static PyType_Slot error_slots[] = {
 
 PyType_Spec error_spec = {
     .name = "_csv.Error",
-    .flags = Py_TPFLAGS_DEFAULT,
+    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
     .slots = error_slots,
 };