Skip to content

quotechar-fix#157

Merged
david-i-berry merged 3 commits intomainfrom
quotechar-fix
Jan 21, 2026
Merged

quotechar-fix#157
david-i-berry merged 3 commits intomainfrom
quotechar-fix

Conversation

@alhelguera
Copy link
Contributor

No description provided.

@david-i-berry
Copy link
Contributor

This does not fix the underlying issue. The issue comes from here:

# quoting
if 'QUOTING' in mappings:
_quoting = mappings['QUOTING']
elif 'quoting' in mappings:
_quoting = mappings['quoting']
else:
_quoting = QUOTING
_quoting = getattr(csv, _quoting)
if 'QUOTECHAR' in mappings:
_quotechar = mappings['QUOTECHAR']
if 'quotechar' in mappings:
_quotechar = mappings['quotechar']
else:
_quotechar = QUOTECHAR

and

reader = csv.reader(fh, delimiter=_delimiter, quoting=_quoting,
quotechar=_quotechar)

There has been a change in behaviour of csv.reader and it has become stricter in validating the quotechar argument leading to the error. We need to fix the arguments passed to csv.reader and to omit the quotechar when quoting in none.

@alhelguera
Copy link
Contributor Author

Hi @david-i-berry check last commit to see the new proposed fix.

@david-i-berry
Copy link
Contributor

david-i-berry commented Jan 21, 2026

Something like

kwargs = {
    "quoting":  _quoting,
    "delimiter": _delimiter
}

if _quoting != csv.QUOTE_NONE:
    if len(_quotechar) == 1:
        kwargs["quotechar"] = _quotechar
    else:
        # warning or error (to be added)
        pass

reader = csv.reader(fh, **kwargs)

@david-i-berry david-i-berry merged commit 33e9c0c into main Jan 21, 2026
10 checks passed
@david-i-berry david-i-berry deleted the quotechar-fix branch January 21, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants