Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong documentation (Language Ref) for unicode and str comparison #73507

Closed
RK-5wWm9h mannequin opened this issue Jan 19, 2017 · 3 comments
Closed

Wrong documentation (Language Ref) for unicode and str comparison #73507

RK-5wWm9h mannequin opened this issue Jan 19, 2017 · 3 comments
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@RK-5wWm9h
Copy link
Mannequin

RK-5wWm9h mannequin commented Jan 19, 2017

BPO 29321
Nosy @vadmium
Superseder
  • bpo-12067: Doc: remove errors about mixed-type comparisons.
  • 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 = None
    closed_at = <Date 2017-05-23.06:16:50.869>
    created_at = <Date 2017-01-19.14:26:43.705>
    labels = ['type-bug', 'docs']
    title = 'Wrong documentation (Language Ref) for unicode and str comparison'
    updated_at = <Date 2017-05-23.06:16:50.867>
    user = 'https://bugs.python.org/RK-5wWm9h'

    bugs.python.org fields:

    activity = <Date 2017-05-23.06:16:50.867>
    actor = 'martin.panter'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-05-23.06:16:50.869>
    closer = 'martin.panter'
    components = ['Documentation']
    creation = <Date 2017-01-19.14:26:43.705>
    creator = 'RK-5wWm9h'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29321
    keywords = []
    message_count = 3.0
    messages = ['285790', '285805', '294234']
    nosy_count = 3.0
    nosy_names = ['docs@python', 'martin.panter', 'RK-5wWm9h']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = '12067'
    type = 'behavior'
    url = 'https://bugs.python.org/issue29321'
    versions = ['Python 2.7']

    @RK-5wWm9h
    Copy link
    Mannequin Author

    RK-5wWm9h mannequin commented Jan 19, 2017

    PROBLEM (IN BRIEF):

    In the currently published 2.7.13 The Python Language Reference manual, section 5.9 "Comparisons" (https://docs.python.org/2/reference/expressions.html#comparisons):

    "If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal..."
    

    This an *incorrect (and misleading) statement*.

    PROPOSED FIX:

    Insert a new sentence, to give this resulting text:

    "If both are numbers, they are converted to a common type. If one is str and the other unicode, they are compared as below. Otherwise, objects of different types always compare unequal..."
    

    DETAILS, JUSTIFICATION, CORRECTNESS, ETC:

    The behaviour that a str and a unicode object -- despite being objects of different types -- may compare equal, is explicitly stated several paragraphs later:

    "* Strings are compared lexicographically using the numeric equivalents (the result of the built-in function ord()) of their characters. Unicode and 8-bit strings are fully interoperable in this behavior. [4]"
    

    Text in the 2.7.13 The Python Standard Library (Library Reference manual) is careful to cover this unicode - str case (https://docs.python.org/2/library/stdtypes.html#comparisons):

    "Objects of different types, except different numeric types and different string types, never compare equal; such objects are ordered consistently but arbitrarily (so that sorting a heterogeneous array yields a consistent result)."
    

    IMPACT AND RELATED BUG:

    The current incorrect text is really misleading for anyone reading the Language Ref. It's easy to see the categorical statement and stop reading because your question has been answered.

    Further, the Library ref about unicode and str (The Python Standard Library (Library Reference manual) section 5.6 "Sequence Types": https://docs.python.org/2/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange), links here. Link text: "(For full details see Comparisons in the language reference.)".

    (Aside: That paragraph has a mistake similar to this present bug: it says "to compare equal, every element must compare equal and the two sequences must be of the same type"; I'll file a separate bug for it.)

    PS: First time reporting a Python bug; following https://docs.python.org/2/bugs.html. Hope I did ok! :-)

    @RK-5wWm9h RK-5wWm9h mannequin assigned docspython Jan 19, 2017
    @RK-5wWm9h RK-5wWm9h mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Jan 19, 2017
    @RK-5wWm9h RK-5wWm9h mannequin changed the title Wrong documentation for unicode and str comparison Wrong documentation (Language Ref) for unicode and str comparison Jan 19, 2017
    @vadmium
    Copy link
    Member

    vadmium commented Jan 19, 2017

    The Python 3 version of this was rewritten in bpo-12067. It would be good to port the new text to the Python 2 version, although that is not straightforward because of various differences between Python 2 and 3.

    That doesn’t rule out making smaller more specific edits in the mean time. However your proposal still seems misleading to only mention str and unicode as special cases. It does not allow for str vs bytearray, set vs frozenset, or custom classes/types implementing their own __eq__() etc methods.

    @vadmium
    Copy link
    Member

    vadmium commented May 23, 2017

    I backported bpo-12067 documentation, so hopefully this is fixed.

    @vadmium vadmium closed this as completed May 23, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant