import gc
import pickle
from test import support
-from test.support import warnings_helper
+from test.support import warnings_helper, import_helper, check_disallow_instantiation
from itertools import permutations
from textwrap import dedent
from collections import OrderedDict
# issue 44089
class Foo(csv.Error): ...
+ @support.cpython_only
+ def test_disallow_instantiation(self):
+ _csv = import_helper.import_module("_csv")
+ for tp in _csv.Reader, _csv.Writer:
+ with self.subTest(tp=tp):
+ check_disallow_instantiation(self, tp)
+
if __name__ == '__main__':
unittest.main()
--- /dev/null
+Prevent possible crash by disallowing instantiation of the
+:class:`!_csv.Reader` and :class:`!_csv.Writer` types.
+The regression was introduced in 3.10.0a4 with PR 23224 (:issue:`14935`).
+Patch by Radislav Chugunov.
.name = "_csv.reader",
.basicsize = sizeof(ReaderObj),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE),
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
.slots = Reader_Type_slots
};
.name = "_csv.writer",
.basicsize = sizeof(WriterObj),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE),
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
.slots = Writer_Type_slots,
};