Skip to content

Improve Bytes and Byte Array Methods doc #47470

Closed

Description

@terryjreedy
BPO 3220
Nosy @birkenfeld, @terryjreedy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2008-07-01.20:08:20.785>
created_at = <Date 2008-06-27.19:47:11.717>
labels = ['docs']
title = 'Improve Bytes and Byte Array Methods doc'
updated_at = <Date 2008-07-01.20:08:20.784>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2008-07-01.20:08:20.784>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2008-07-01.20:08:20.785>
closer = 'georg.brandl'
components = ['Documentation']
creation = <Date 2008-06-27.19:47:11.717>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 3220
keywords = []
message_count = 2.0
messages = ['68848', '69064']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'terry.reedy']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue3220'
versions = ['Python 3.0']

Activity

  1. terryjreedy commented on Jun 27, 2008

    @terryjreedy
    MemberAuthor

    Lib Ref/Built-in Types/Sequence Types/Bytes and Byte Array Methods

    The following set/frozenset and dict sections repeat (and for dicts,
    expands upon) the constructor interface from the Built-in Functions
    section. The sequence type sections do not. There should as least be a
    reference back. "For the constructor interface, see xxx"

    Similarly there is no mention here of the difference between bytes and
    bytearray, as there is below for the difference between set and
    frozenset. I think there should be here, in this section, even though
    there is back in Built-in Functions.

    (Sets/frozenset have the opposite problem in that Built-in Functions
    makes no mention that one is mutable and the other is not. I also think
    just one word for each should be added there too.)

    "The bytes and bytearray types have an additional class method:
    bytes.fromhex(string) " should be followed by
    "bytearray.fromhex(string)" and
    "This bytes class method returns a bytes object," changed to
    "These class methods return a bytes or bytearray object,"

    I don't think the line 'Example:' is needed.

    A thread today on the Py3 lists again brought up the issue that just as
    bytes can be created by either a literal or class call, they could be
    represented on output by either, with possible confusion.
    Guido responded

    Only if you didn't know that b'' is an alternative to bytes(). The b''
    notation is so much more compact and so much more helpful that I
    really don't want to go back to it. We will somehow have to deal with
    this through education and documentation.

    I suggest adding at the end:
    "Just as a bytes objects can be constructed either with a literal or a
    class constructor call, they could be represented on output either by a
    literal or class constructor call. The literal was chosen as being
    shorter, generally more useful, and consistent with how other classes
    are displayed. Similarly, the display of bytearrays uses the
    corresponding bytes literal. If you want to see the bytes of either
    class as integers, use tuple.

    >>> a, b = b'abc', bytes((1,2,3))
    >>> a,b
    (b'abc', b'\x01\x02\x03')
    >>> tuple(a), tuple(b)
    ((97, 98, 99), (1, 2, 3))
    >>> c = bytearray(a)
    >>> c, tuple(c)
    (bytearray(b'abc'), (97, 98, 99))
    "
  2. added
    docs
    on Jun 27, 2008
  3. birkenfeld commented on Jul 1, 2008

    @birkenfeld
    Member

    Lib Ref/Built-in Types/Sequence Types/Bytes and Byte Array Methods

    The following set/frozenset and dict sections repeat (and for dicts,
    expands upon) the constructor interface from the Built-in Functions
    section. The sequence type sections do not. There should as least be a
    reference back. "For the constructor interface, see xxx"

    Right -- I need to reorganize that section a bit more, and this is on
    the list to do.

    Similarly there is no mention here of the difference between bytes and
    bytearray, as there is below for the difference between set and
    frozenset. I think there should be here, in this section, even though
    there is back in Built-in Functions.

    The difference is mentioned under the "sequence types" heading.

    (Sets/frozenset have the opposite problem in that Built-in Functions
    makes no mention that one is mutable and the other is not. I also think
    just one word for each should be added there too.)

    "The bytes and bytearray types have an additional class method:
    bytes.fromhex(string) " should be followed by
    "bytearray.fromhex(string)" and
    "This bytes class method returns a bytes object," changed to
    "These class methods return a bytes or bytearray object,"

    Agreed.

    I don't think the line 'Example:' is needed.

    Yep.

    A thread today on the Py3 lists again brought up the issue that just as
    bytes can be created by either a literal or class call, they could be
    represented on output by either, with possible confusion.
    Guido responded
    > Only if you didn't know that b'' is an alternative to bytes(). The b''
    > notation is so much more compact and so much more helpful that I
    > really don't want to go back to it. We will somehow have to deal with
    > this through education and documentation.

    I suggest adding at the end:
    "Just as a bytes objects can be constructed either with a literal or a
    class constructor call, they could be represented on output either by a
    literal or class constructor call. The literal was chosen as being
    shorter, generally more useful, and consistent with how other classes
    are displayed. Similarly, the display of bytearrays uses the
    corresponding bytes literal. If you want to see the bytes of either
    class as integers, use tuple.

    >>> a, b = b'abc', bytes((1,2,3))
    >>> a,b
    (b'abc', b'\x01\x02\x03')
    >>> tuple(a), tuple(b)
    ((97, 98, 99), (1, 2, 3))
    >>> c = bytearray(a)
    >>> c, tuple(c)
    (bytearray(b'abc'), (97, 98, 99))
    "

    The same section that documents the bytes/bytearray difference also already
    mentions this; I've amended it a bit to include the bit about
    representation.

    Committed changes as r64627.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docs

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions