[Python-ideas] More alternate constructors for builtin type

Steven D'Aprano steve at pearwood.info
Tue May 7 05:17:43 EDT 2019


On Tue, May 07, 2019 at 12:57:49AM +0000, Josh Rosenberg wrote:

> bytes.ord is a bad name, given the behavior would be the opposite of ord
> (ord converts length one str to int, not int to length one str).

D'oh!

I mean, well done, that was a test and you passed!

*wink*

Sorry for the confusion, yes, I got ord/chr confused in my head.


> PEP467 (currently deferred to 3.9 or later) does have proposals for this
> case, either bytes.byte (old proposal:
> https://legacy.python.org/dev/peps/pep-0467/#addition-of-explicit-single-byte-constructors
> ) or bytes.fromord/a top level built-in named bchr in the new version of
> the PEP (
> https://www.python.org/dev/peps/pep-0467/#addition-of-bchr-function-and-explicit-single-byte-constructors
> ). So if that's the way we want to go, we could just push forward on
> PEP467.

My personal sense is that generating a single byte from an ordinal is 
not common enough to justify a new builtin, but I don't have a strong 
opposition to the concept as such.

But I am very adverse to the suggested name. Not only is "bchr" 
inelegant, but now that regular strings are Unicode, we really ought to 
avoid perpetuating the idea that single bytes are characters and text 
strings are bytes more than we really have to.



-- 
Steven


More information about the Python-ideas mailing list