homepage

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.

Author nascheme
Recipients nascheme
Date 2014年01月16日.21:33:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389907989.35.0.952766608541.issue20284@psf.upfronthosting.co.za>
In-reply-to
Content
This is a very rough, proof of concept patch that implements %-style formatting for bytes objects. Currently it calls __format__ with a bytes argument and expects a bytes result. I've only implemented 
support for bytes formatting for the 'long' object.
Expected behavior:
>>> b'%s' % b'hello'
b'hello'
>>> b'%s' % 'hello'
TypeError is raised
>>> b'%s' % 123
b'123'
>>> b'%d' % 123
b'123'
Some issues:
- %s support is incomplete, needs to handle width and padding. I think it should be done in formatbytes().
- PyBytes_Format function very likely has bugs, I copied it mostly from Python 2 and quickly made it run, I did very little testing.
- long__format__ with a bytes argument is inefficient. It creates temporary Python objects that could be avoided. %-style formatting on bytes will be much less efficient than str in Python 2. We could inline the handling of certain types in PyBytes_Format, maybe longs only would be sufficent.
- I'm not sure overloading __format__ is the best approach. Maybe we should introduce a new method, say __ascii__ instead and have PyBytes_Format call that.
History
Date User Action Args
2014年01月16日 21:33:09naschemesetrecipients: + nascheme
2014年01月16日 21:33:09naschemesetmessageid: <1389907989.35.0.952766608541.issue20284@psf.upfronthosting.co.za>
2014年01月16日 21:33:09naschemelinkissue20284 messages
2014年01月16日 21:33:09naschemecreate

AltStyle によって変換されたページ (->オリジナル) /