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
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.
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.
Activity
serhiy-storchaka commentedon Aug 17, 2014
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.
serhiy-storchaka commentedon Aug 19, 2014
BDFL have approved the idea (http://permalink.gmane.org/gmane.comp.python.devel/149000). Could anyone please make the review of concrete patch?
serhiy-storchaka commentedon Sep 5, 2014
If there are no objections I'll commit the patch soon.
vstinner commentedon Sep 5, 2014
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"):
http://en.wikipedia.org/wiki/Null_character
I talking about the error message because you changed it in a few places.
vstinner commentedon Sep 5, 2014
You may also take a look at these 2 issues: bpo-13617 and bpo-21147 (not directly related to this oe).
serhiy-storchaka commentedon Sep 5, 2014
Thank you Victor. Here is a patch which is synchronized with the tip and addresses your comment about a null character.
serhiy-storchaka commentedon Sep 6, 2014
Simplified a code in getargs.c as suggested by Victor.
vstinner commentedon Sep 6, 2014
The latest patch looks good to me.
python-dev commentedon Sep 6, 2014
New changeset 25032ec29315 by Serhiy Storchaka in branch 'default':
Issue bpo-22215: Now ValueError is raised instead of TypeError when str or bytes
http://hg.python.org/cpython/rev/25032ec29315
serhiy-storchaka commentedon Sep 6, 2014
Thank you for your review Victor.