mirror of
https://github.com/python/cpython.git
synced 2025-10-12 18:02:39 +00:00
gh-104265 Disallow instantiation of _csv.Reader
and _csv.Writer
(#104266)
This commit is contained in:
parent
c0ece3dc97
commit
06c2a4858b
3 changed files with 14 additions and 3 deletions
|
@ -10,7 +10,7 @@ import csv
|
||||||
import gc
|
import gc
|
||||||
import pickle
|
import pickle
|
||||||
from test import support
|
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 itertools import permutations
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
@ -1430,5 +1430,12 @@ class MiscTestCase(unittest.TestCase):
|
||||||
# issue 44089
|
# issue 44089
|
||||||
class Foo(csv.Error): ...
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
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.
|
|
@ -1000,7 +1000,7 @@ PyType_Spec Reader_Type_spec = {
|
||||||
.name = "_csv.reader",
|
.name = "_csv.reader",
|
||||||
.basicsize = sizeof(ReaderObj),
|
.basicsize = sizeof(ReaderObj),
|
||||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
|
.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
|
.slots = Reader_Type_slots
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1431,7 +1431,7 @@ PyType_Spec Writer_Type_spec = {
|
||||||
.name = "_csv.writer",
|
.name = "_csv.writer",
|
||||||
.basicsize = sizeof(WriterObj),
|
.basicsize = sizeof(WriterObj),
|
||||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
|
.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,
|
.slots = Writer_Type_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue