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
{{ message }}
Repository navigation
Codecs should raise precise UnicodeDecodeError or UnicodeEncodeError #85287
A number of codecs raise bare UnicodeError, rather than Unicode{Decode,Encode}Error. Example:
File "/home/antoine/miniconda3/envs/pyarrow/lib/python3.7/encodings/utf_16.py", line 67, in _buffer_decode
raise UnicodeError("UTF-16 stream does not start with BOM")
@pitrou Regarding the start and end values that are used to communicate where the bad values are, what should be done if the absolute location cannot be determined? There are portions of code, such as with punycode, where the encoded byes is divided up for processing and the only positional data available at the time of exception is the relative position within the given segment. Should 0,0 be used in a situation like this?
@methane I was told you may be an interested party that could answer questions about unicode exception handling. Regarding my question above, what are you expectations with regards to the reported start and end positions?
Decided to give this a shot as I see it's still unresolved on the main branch. Made some decisions about how to do certain things just so I could ship something, but very much open to discussion on other approaches.
The biggest question is whether it's worth having the codec functions save their original arguments just so they can be shown if an exception happens. It might not even be extra memory overhead since the caller is probably still holding a reference to the argument object in most cases.
Also this is my first time looking at the CPython codebase and my first time using the C API so please let me know if I'm making any beginner mistakes.
Activity
pitrou commentedon Jun 25, 2020
A number of codecs raise bare UnicodeError, rather than Unicode{Decode,Encode}Error. Example:
File "/home/antoine/miniconda3/envs/pyarrow/lib/python3.7/encodings/utf_16.py", line 67, in _buffer_decode
raise UnicodeError("UTF-16 stream does not start with BOM")
A more complete list can be found here:
https://gist.github.com/pitrou/60594b28d8e47edcdb97d9b15d5f9866
srinivasreddy commentedon Jun 25, 2020
This looks like an easy task. Shall I create a PR?
eamanu commentedon Jun 25, 2020
Hi,
IMO this can be mark as an easy issue.
@thatiparthy please, go ahead
7 remaining items
mblahay commentedon Apr 26, 2023
@SahillMulani, I am looking to perhaps work on this issue, but will avoid it if you are. Please let me know what your status is.
mblahay commentedon Apr 26, 2023
@pitrou Regarding the start and end values that are used to communicate where the bad values are, what should be done if the absolute location cannot be determined? There are portions of code, such as with punycode, where the encoded byes is divided up for processing and the only positional data available at the time of exception is the relative position within the given segment. Should 0,0 be used in a situation like this?
mblahay commentedon Apr 26, 2023
@methane I was told you may be an interested party that could answer questions about unicode exception handling. Regarding my question above, what are you expectations with regards to the reported start and end positions?
methane commentedon May 25, 2023
It seems this issue is not fixed yet.
c
python:
fix issue pythongh-85287
jjsloboda commentedon Jan 3, 2024
Decided to give this a shot as I see it's still unresolved on the
mainbranch. Made some decisions about how to do certain things just so I could ship something, but very much open to discussion on other approaches.The biggest question is whether it's worth having the codec functions save their original arguments just so they can be shown if an exception happens. It might not even be extra memory overhead since the caller is probably still holding a reference to the argument object in most cases.
Also this is my first time looking at the CPython codebase and my first time using the C API so please let me know if I'm making any beginner mistakes.
gh-85287: Change codecs to raise precise UnicodeEncodeError and Unico…
pythongh-85287: Change codecs to raise precise UnicodeEncodeError and…
pythongh-85287: Change codecs to raise precise UnicodeEncodeError and…
pythongh-85287: Change codecs to raise precise UnicodeEncodeError and…
nineteendo commentedon May 19, 2024
Isn't this fixed?