You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Modules/_csv.c, the DIALECT_GETATTR macro in dialect_new() calls PyErr_Clear() unconditionally when PyObject_GetAttrString() fails. This silently swallows all exception types including MemoryError, KeyboardInterrupt, RuntimeError, etc.
All 8 dialect attributes are affected: delimiter, doublequote, escapechar, lineterminator, quotechar, quoting, skipinitialspace, strict.
Fix
#defineDIALECT_GETATTR(v, n) \
do { \
if (v == NULL) { \
v = PyObject_GetAttrString(dialect, n); \
if (v == NULL) { \
if (PyErr_ExceptionMatches(PyExc_AttributeError)) \
PyErr_Clear(); \
else \
goto err; \
} \
} \
} while (0)
Activity
_csv:DIALECT_GETATTRmacro silently masks non-AttributeErrorexceptions #145967 as a duplicate of this issueStanFromIreland commentedon Mar 15, 2026
Do you want to write a patch?
raminfp commentedon Mar 15, 2026
@StanFromIreland Sure, done.
gh-145966: Fix _csv DIALECT_GETATTR macro silently masking non-Attrib…
encukou commentedon Mar 17, 2026
Thank you @raminfp for the fix, and @picnixz for the review!
This is a behaviour change; I think it's safer to skip backporting.
pythongh-145966: Fix _csv DIALECT_GETATTR macro silently masking non-…