GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs: operator dunder (`__add__`, et al.) invocations described incorrectly · Issue #85872 · python/cpython

docs: operator dunder (__add__, et al.) invocations described incorrectly #85872

New issue
Copy link
New issue
Copy link
Closed
Closed
docs: operator dunder (__add__, et al.) invocations described incorrectly#85872
Copy link
Labels
3.10 (EOL)end of lifeend of life3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirtype-featureA feature request or enhancementA feature request or enhancement

Description

wchargin
mannequin
opened on Sep 3, 2020
Issue body actions
BPO 41706
Nosy @brettcannon, @wchargin
PRs
  • bpo-41706: Fix dunder operator invocation docs #22084
  • 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 2021-08-05.00:08:48.071>
    created_at = <Date 2020-09-03.20:30:50.412>
    labels = ['3.7', '3.8', '3.9', '3.10', 'type-feature', 'docs']
    title = 'docs: operator dunder (`__add__`, et al.) invocations described incorrectly'
    updated_at = <Date 2021-08-05.00:08:48.071>
    user = 'https://github.com/wchargin'

    bugs.python.org fields:

    activity = <Date 2021-08-05.00:08:48.071>
    actor = 'brett.cannon'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-08-05.00:08:48.071>
    closer = 'brett.cannon'
    components = ['Documentation']
    creation = <Date 2020-09-03.20:30:50.412>
    creator = 'wchargin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41706
    keywords = ['patch']
    message_count = 2.0
    messages = ['376316', '398954']
    nosy_count = 3.0
    nosy_names = ['brett.cannon', 'docs@python', 'wchargin']
    pr_nums = ['22084']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41706'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    Activity

    1. wchargin commented on Sep 3, 2020

      @wchargin
      wcharginmannequin
      on Sep 3, 2020
      MannequinAuthor
      More actions

      The operator override dunder methods, like __add__, are described in
      the “Data model” docs here:
      https://docs.python.org/3.10/reference/datamodel.html#object.__add__

      Those docs say:

      For instance, to evaluate the expression x + y, where x is an
      instance of a class that has an __add__() method, x.__add__(y) is
      called.

      But this is not correct: x + y always uses type(x).__add__, which
      may be different from x.__add__ if __add__ has been set directly on
      the instance.

      Demonstration:

      class C:
          def __add__(self, other):
              return "from class"
      
      
      c = C()
      print(c + c)  # prints "from class"
      
      c.__add__ = lambda other: "from instance"
      print(c.__add__(c))  # prints "from instance"
      print(type(c).__add__(c, c))  # prints "from class"
      
      print(c + c)  # prints "from class"!
      

      The same issue appears in the reversed operator dunder (__radd__,
      et al.) docs below.

      I have a patch that I can submit as a PR; just need a bpo number.

    2. wchargin
      added
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      on Sep 3, 2020
    3. wchargin
      assigned
      docspython
      on Sep 3, 2020
    4. wchargin
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      type-featureA feature request or enhancementA feature request or enhancement
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      on Sep 3, 2020
    5. wchargin
      assigned
      docspython
      on Sep 3, 2020
    6. wchargin
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      type-featureA feature request or enhancementA feature request or enhancement
      on Sep 3, 2020
    7. brettcannon commented on Aug 4, 2021

      @brettcannon
      brettcannon
      on Aug 4, 2021
      Member
      More actions

      New changeset 80f33f2 by William Chargin in branch 'main':
      bpo-41706: Fix special method invocation docs to mention using type() (GH-22084)
      80f33f2

    8. brettcannon
      closed this as completedon Aug 5, 2021
    9. brettcannon
      closed this as completedon Aug 5, 2021
    10. ezio-melotti
      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

    No one assigned

      Labels

      3.10 (EOL)end of lifeend of life3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirtype-featureA feature request or enhancementA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.