PEP 467: ascii constructors removed (GH-3603)

This commit is contained in:
Ethan Furman 2023-12-23 16:01:48 -08:00 committed by GitHub
parent 5f200941a3
commit 89f5afbb21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 31 deletions

View File

@ -20,7 +20,6 @@ This PEP proposes five small adjustments to the APIs of the ``bytes`` and
* Add ``fromsize`` alternative constructor
* Add ``fromint`` alternative constructor
* Add ``ascii`` alternative constructor
* Add ``getbyte`` byte retrieval method
* Add ``iterbytes`` alternative iterator
@ -120,36 +119,6 @@ negative numbers. The documentation of the new methods will refer readers to
``int.to_bytes`` for use cases where handling of arbitrary integers is needed.
Addition of "ascii" constructors
--------------------------------
In Python 2 converting an object, such as the integer ``123``, to bytes (aka the
Python 2 ``str``) was as simple as::
>>> str(123)
'123'
With Python 3 that became the more verbose::
>>> b'%d' % 123
or even::
>>> str(123).encode('ascii')
This PEP proposes that an ``ascii`` method be added to ``bytes`` and ``bytearray``
to handle this use-case::
>>> bytes.ascii(123)
b'123'
Note that ``bytes.ascii()`` would handle simple ascii-encodable text correctly,
unlike the ``ascii()`` built-in::
>>> ascii("hello").encode('ascii')
b"'hello'"
Addition of "getbyte" method to retrieve a single byte
------------------------------------------------------