STINNER Victor <victor.stin...@haypocalc.com> added the comment:

Some examples of functions using "s" format:
 * str.encode(encoding, errors), bytes.decode(encoding, errors): both arguments 
have to be unicode strings
 * compile(source, filename, mode, ...): filename and mode have to be unicode 
strings
 * crypt.crypt(word, salt): both arguments have to be unicode strings

I think that crypt() should also accept bytes, but not str.encode() nor 
bytes.decode().

Some examples of functions using "z" format:
 * _locale.bindtextdomain(domain, dirname): dirname uses "z" format and so 
accepts str, bytes or buffer compatible object. It should use 
PyUnicode_FSConverter() instead. But I agree that bytes is welcomed here.
 * readline.(write_history_file|read_init_file|read_history_file) functions do 
use "z" to parse a filename. PyUnicode_FSConverter() would also be better, but 
in this case "z" is better than "s" :-)

I don't know why "s" and "z" are different about bytes, but it will be 
difficult to change it without changing a lot ot code (all functions using 
these formats). I tried to reject types different than str for "z": most tests 
of the test suite fail. I tried to accept bytes for "s" format: 
"unicode".encode(b'abc') does segfault.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8949>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to