From 3e44e9af9ea4c5e82912a01f256d4abcae96f32b Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 12 May 2021 07:02:46 -0700 Subject: [PATCH] bpo-44089: Allow subclassing of ``csv.Error`` (GH-26008) (GH-26066) * fix subclass error * Update 2021-05-09-22-52-34.bpo-44089.IoANsN.rst (cherry picked from commit 2b458c1dba4058c808fde25226bb2d91c5a909ca) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> --- Lib/test/test_csv.py | 3 +++ .../next/Library/2021-05-09-22-52-34.bpo-44089.IoANsN.rst | 2 ++ Modules/_csv.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2021-05-09-22-52-34.bpo-44089.IoANsN.rst diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 2411a91110dd..a1e050acd2a0 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -1237,6 +1237,9 @@ def test__all__(self): 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 index 000000000000..b9bd963582fd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-05-09-22-52-34.bpo-44089.IoANsN.rst @@ -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). diff --git a/Modules/_csv.c b/Modules/_csv.c index cade1ca9d47f..bdb67fdb4876 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -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, };