This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: "embedded NUL character" exceptions
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2014-08-17 14:43 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
valueerror_embedded_nul_character.diff serhiy.storchaka, 2014-08-17 14:43 review
valueerror_embedded_nul_character_2.patch serhiy.storchaka, 2014-09-05 09:50 review
valueerror_embedded_nul_character_3.patch serhiy.storchaka, 2014-09-06 06:29 review
Messages (10)
msg225447 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-17 14:43
Currently most functions which accepts string only without embedded NUL character, raise TypeError. Proposed patch change exception type to more consistent ValueError. It also unifies error messages.

I have opened a discussion on Python-Dev.
msg225518 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-19 07:02
BDFL have approved the idea ( Could anyone please make the review of concrete patch?
msg226403 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-05 07:07
If there are no objections I'll commit the patch soon.
msg226410 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-05 08:56
> If there are no objections I'll commit the patch soon.

Replacing TypeError with ValueError is fine. TypeError was a bad choice. If an application relies on TypeError to check for null character, it's easy to replace "except TypeError:" with "except (TypeError, ValueError):" to stay compatible with Python < 3.5.

Instead of "NUL character" (and "NUL byte), I had prefer "null character" (and "null byte"):

I talking about the error message because you changed it in a few places.
msg226411 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-05 08:57
You may also take a look at these 2 issues: #13617 and #21147 (not directly related to this oe).
msg226413 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-05 09:50
Thank you Victor. Here is a patch which is synchronized with the tip and addresses your comment about a null character.
msg226472 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 06:21
Simplified a code in getargs.c as suggested by Victor.
msg226478 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-06 09:06
The latest patch looks good to me.
msg226495 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-09-06 17:08
New changeset 25032ec29315 by Serhiy Storchaka in branch 'default':
Issue #22215: Now ValueError is raised instead of TypeError when str or bytes
msg226497 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 17:30
Thank you for your review Victor.
Date User Action Args
2022-04-11 14:58:07adminsetgithub: 66411
2014-09-06 17:31:30serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-09-06 17:30:58serhiy.storchakasetmessages: + msg226497
2014-09-06 17:08:25python-devsetmessages: + msg226495
2014-09-06 09:06:57vstinnersetmessages: + msg226478
2014-09-06 06:29:27serhiy.storchakasetfiles: + valueerror_embedded_nul_character_3.patch
2014-09-06 06:23:08serhiy.storchakasetfiles: - valueerror_embedded_nul_character_3.patch
2014-09-06 06:21:39serhiy.storchakasetfiles: + valueerror_embedded_nul_character_3.patch

messages: + msg226472
2014-09-05 09:50:37serhiy.storchakasetfiles: + valueerror_embedded_nul_character_2.patch

messages: + msg226413
2014-09-05 08:57:48vstinnersetmessages: + msg226411
2014-09-05 08:56:51vstinnersetnosy: + vstinner
messages: + msg226410
2014-09-05 07:07:03serhiy.storchakasetmessages: + msg226403
2014-08-30 20:59:51r.david.murraysetmessages: - msg226149
2014-08-30 20:57:29python-devsetnosy: + python-dev
messages: + msg226149
2014-08-19 07:02:46serhiy.storchakasetassignee: serhiy.storchaka
2014-08-19 07:02:20serhiy.storchakasetmessages: + msg225518
2014-08-17 14:43:54serhiy.storchakacreate