Skip to content

Commit e207cc1

Browse files
authored
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'.
1 parent 391659b commit e207cc1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/csv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def _validate(self):
113113
try:
114114
_Dialect(self)
115115
except TypeError as e:
116-
# We do this for compatibility with py2.3
117-
raise Error(str(e))
116+
# Re-raise to get a traceback showing more user code.
117+
raise Error(str(e)) from None
118118

119119
class excel(Dialect):
120120
"""Describe the usual properties of Excel-generated CSV files."""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
When csv.Error is raised when handling TypeError, do not print the TypeError
2+
traceback.

0 commit comments

Comments
 (0)