diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-13 23:20:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 23:20:28 (GMT) |
commit | fe73509c5ba3844b45a2253967522531ab80c849 (patch) | |
tree | 796175ecfbd0d614b88f90b1390b1bc942e13079 /Lib/test/test_csv.py | |
parent | a3d20bfee38c71df88d69064d47fe98a1d59e624 (diff) | |
download | cpython-fe73509c5ba3844b45a2253967522531ab80c849.zip cpython-fe73509c5ba3844b45a2253967522531ab80c849.tar.gz cpython-fe73509c5ba3844b45a2253967522531ab80c849.tar.bz2 |
bpo-44630: Fix assertion errors in csv module (GH-27127)
Fix incorrect handling of exceptions when interpreting dialect objects in
the csv module. Not clearing exceptions between calls to
PyObject_GetAttrString() causes assertion failures in pydebug mode (or with
assertions enabled).
Add a minimal test that would've caught this (passing None as dialect, or
any object that isn't a csv.Dialect subclass, which the csv module allows
and caters to, even though it is not documented.) In pydebug mode, the test
triggers the assertion failure in the old code.
Contributed-By: T. Wouters [Google]
(cherry picked from commit 0093876328afa330224c9d887c18dee0b3117852)
Co-authored-by: T. Wouters <thomas@python.org>
Diffstat (limited to 'Lib/test/test_csv.py')
-rw-r--r-- | Lib/test/test_csv.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 2dab17d..89fec4b 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -442,9 +442,15 @@ class TestDialectRegistry(unittest.TestCase): class testUni(csv.excel): delimiter = "\u039B" + class unspecified(): + # A class to pass as dialect but with no dialect attributes. + pass + csv.register_dialect('testC', testC) try: self.compare_dialect_123("1,2,3\r\n") + self.compare_dialect_123("1,2,3\r\n", dialect=None) + self.compare_dialect_123("1,2,3\r\n", dialect=unspecified) self.compare_dialect_123("1\t2\t3\r\n", testA) self.compare_dialect_123("1:2:3\r\n", dialect=testB()) self.compare_dialect_123("1|2|3\r\n", dialect='testC') |