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

Document that object.__eq__ implements a is b #86076

Closed
brettcannon opened this issue Oct 2, 2020 · 10 comments
Closed

Document that object.__eq__ implements a is b #86076

brettcannon opened this issue Oct 2, 2020 · 10 comments
Assignees
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir

Comments

@brettcannon
Copy link
Member

BPO 41910
Nosy @brettcannon, @terryjreedy, @miss-islington
PRs
  • bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ #22874
  • [3.9] bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) #22876
  • [3.8] bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) #22877
  • bpo-41910: move news entry  #23695
  • [3.9] bpo-41910: move news entry (GH-23695) #23697
  • [3.8] bpo-41910: move news entry (GH-23695) #23698
  • 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/brettcannon'
    closed_at = <Date 2020-10-22.01:33:19.923>
    created_at = <Date 2020-10-02.15:22:02.868>
    labels = ['3.8', '3.9', '3.10', 'docs']
    title = 'Document that object.__eq__ implements `a is b`'
    updated_at = <Date 2020-12-08.18:00:36.499>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2020-12-08.18:00:36.499>
    actor = 'terry.reedy'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2020-10-22.01:33:19.923>
    closer = 'terry.reedy'
    components = ['Documentation']
    creation = <Date 2020-10-02.15:22:02.868>
    creator = 'brett.cannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41910
    keywords = ['patch']
    message_count = 9.0
    messages = ['377816', '377845', '379264', '379265', '379266', '379267', '379269', '382744', '382754', '382755']
    nosy_count = 4.0
    nosy_names = ['brett.cannon', 'terry.reedy', 'docs@python', 'miss-islington']
    pr_nums = ['22874', '22876', '22877', '23695', '23697', '23698']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue41910'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @brettcannon
    Copy link
    Member Author

    If you look at the data model for object.__eq__ (https://docs.python.org/3.8/reference/datamodel.html#object.__eq__) you will see that it doesn't mention any actual implementation (unlike for ne). But https://github.com/python/cpython/blob/v3.8.3/Objects/typeobject.c#L3834-L3880 shows that object.eq actually does have an implementation of a is b/id(a) == id(b).

    @brettcannon brettcannon added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir labels Oct 2, 2020
    @brettcannon brettcannon added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir labels Oct 2, 2020
    @brettcannon brettcannon assigned brettcannon and unassigned docspython Oct 2, 2020
    @terryjreedy
    Copy link
    Member

    The word 'object' in this section is a bit confusing because it refers to any Python object, not to base class 'object' or an instance thereof. I suspect that this usage predates the introduction of the latter in 2.2.

    This interpretation is required for sentences like "By default, __ne__() delegates to __eq__() and inverts the result unless it is NotImplemented." and "If a class does not define an __eq__() method ..." (in the __hash__ entry) to make sense. I think that the meaning of 'object' should be stipulated at the top of the section and mention the existence of base class 'object', and maybe list which of the following methods it has, and that they are inherited by subclasses.

    The base class __eq__ implementation is implied in this paragraph in the __hash__ entry.

    "User-defined classes have __eq__() and __hash__() methods by default; with them, all objects compare unequal (except with themselves) and x.__hash__() returns an appropriate value such that x == y implies both that x is y and hash(x) == hash(y)."

    I think it worthwhile explaining that user classes get these defaults by inheriting them (and others) from 'object', and that the implication follows from inheriting a particular base class implementation of __eq__. To put it another way, I believe the quoted paragraph makes the definition a Python requirement rather than just a CPython implementation detail.

    @miss-islington
    Copy link
    Contributor

    New changeset 3c69f0c by Brett Cannon in branch 'master':
    bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874)
    3c69f0c

    @terryjreedy
    Copy link
    Member

    New changeset c3538b8 by Miss Skeleton (bot) in branch '3.9':
    bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) (bpo-22876)
    c3538b8

    @terryjreedy
    Copy link
    Member

    New changeset b2b3803 by Miss Skeleton (bot) in branch '3.8':
    bpo-41910: specify the default implementations of object.__eq__ and object.__ne__ (GH-22874) (bpo-22877)
    b2b3803

    @terryjreedy
    Copy link
    Member

    Brett, I presume you want this closed.

    @brettcannon
    Copy link
    Member Author

    Thanks, Terry!

    @terryjreedy
    Copy link
    Member

    New changeset 4aa6785 by Terry Jan Reedy in branch 'master':
    bpo-41910: move news entry (GH-23695)
    4aa6785

    @terryjreedy
    Copy link
    Member

    New changeset b947b30 by Terry Jan Reedy in branch '3.8':
    [3.8] bpo-41910: move news entry (GH-23698)
    b947b30

    @terryjreedy
    Copy link
    Member

    New changeset a3a4bf3 by Terry Jan Reedy in branch '3.9':
    [3.9] bpo-41910: move news entry (GH-23697)
    a3a4bf3

    @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
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants