Petitioning for bytes.format()?

Gregory Szorc gregory.szorc at gmail.com
Thu Jun 1 16:46:36 UTC 2017


bytes.format() doesn't exist in Python 3.

I was watching some PyCon videos. At least one speaker made a comment that
the % formatting operator is mainly there for backwards compatibility with
Python 2 and str.format() is the future.

If str.format() is the future and % formatting of bytes was re-added in
Python 3.5 to facilitate consumers (like Mercurial) that do bytes
everywhere, shouldn't bytes.format() exist to facilitate migrating away
from the legacy % operator?

Is petitioning for bytes.format() something we want to engage the Python
community on? If there are features that don't make sense for bytes types,
I'm sure we could settle for a subset of the feature that enabled basic
variable insertion like the % operator.

Also, in a future Python 3 only world where % is not supported or desired,
how does one do string formatting type things for bytes anyway?
Concatenation and io.BytesIO() are what immediately come to mind. But these
aren't exactly elegant nor do they have decent performance. It feels like
not having string formatting for bytes excludes bytes from the Zen of
Python :/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170601/a9c38204/attachment.html>


More information about the Mercurial-devel mailing list