https://github.com/python/cpython/commit/e207cc181fbb0ceb30542fd0d68140c916305f57
commit: e207cc181fbb0ceb30542fd0d68140c916305f57
branch: main
author: Terry Jan Reedy <[email protected]>
committer: terryjreedy <[email protected]>
date: 2024-02-04T20:57:54-05:00
summary:

gh-114628: Display csv.Error without context (#115005)

When cvs.Error is raised when TypeError is caught,
the TypeError display and 'During handling' note is just noise
with duplicate information.  Suppress with 'from None'.

files:
A Misc/NEWS.d/next/Library/2024-02-04-13-17-33.gh-issue-114628.WJpqqS.rst
M Lib/csv.py

diff --git a/Lib/csv.py b/Lib/csv.py
index a079279b8b8cbc..75e35b23236795 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -113,8 +113,8 @@ def _validate(self):
         try:
             _Dialect(self)
         except TypeError as e:
-            # We do this for compatibility with py2.3
-            raise Error(str(e))
+            # Re-raise to get a traceback showing more user code.
+            raise Error(str(e)) from None
 
 class excel(Dialect):
     """Describe the usual properties of Excel-generated CSV files."""
diff --git 
a/Misc/NEWS.d/next/Library/2024-02-04-13-17-33.gh-issue-114628.WJpqqS.rst 
b/Misc/NEWS.d/next/Library/2024-02-04-13-17-33.gh-issue-114628.WJpqqS.rst
new file mode 100644
index 00000000000000..8138adc62c95f3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-02-04-13-17-33.gh-issue-114628.WJpqqS.rst
@@ -0,0 +1,2 @@
+When csv.Error is raised when handling TypeError, do not print the TypeError
+traceback.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to