I'm attaching v2 of my proposed patch. This one is quite a bit better, IMHO.
- Introduce __ascii__ as a special method, like __str__ but required to exist only if an ASCII-only format exists.
- Extract PyString_Format from Python 2.7 and update it for PyBytes.
- %c only accepts integers, not single character strs, maybe should
accept length one byte objects.
- add %a, should be useful for debugging
- %s calls __bytes__ or __ascii__, otherwise gives a TypeError, should
eventually support buffer API
- number formats work as they do in Python 2. |