Skip to content

Weakref proxy missing pass throughs for hash() and reversed() #84703

Closed

Description

@rhettinger
BPO 40523
Nosy @rhettinger, @pablogsal
PRs
  • bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects #19946
  • 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 2020-05-05.21:58:36.117>
    created_at = <Date 2020-05-05.18:34:38.699>
    labels = ['3.8', 'type-bug', 'library', '3.9']
    title = 'Weakref proxy missing pass throughs for hash() and reversed()'
    updated_at = <Date 2020-05-05.21:58:36.116>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2020-05-05.21:58:36.116>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-05.21:58:36.117>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2020-05-05.18:34:38.699>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40523
    keywords = ['patch']
    message_count = 2.0
    messages = ['368197', '368211']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'pablogsal']
    pr_nums = ['19946']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40523'
    versions = ['Python 3.8', 'Python 3.9']

    Activity

    1. rhettinger commented on May 5, 2020

      @rhettinger
      ContributorAuthor
      from weakref import proxy
      
      class Alpha:
          def __len__(self):
              return 3
          def __reversed__(self):
              return iter('cba')
          def __hash__(self):
              return hash('abc')
      
      a = Alpha()
      
      # Direct use of the instance works
      print(len(a))
      print(list(reversed(a)))
      print(hash(a))
      
      # Proxies can use the dunder methods directly
      r = proxy(a)
      print(r.__len__())
      print(list(r.__reversed__()))
      print(r.__hash__())

      # Proxy fails for __reversed__ and __hash__
      print(len(r), 'This succeeds')
      try:
      print(list(reversed(r)))
      except TypeError:
      print('reverse(r) failed')
      try:
      print(hash(r))
      except TypeError:
      print('hash(r) failed')

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on May 5, 2020
    3. pablogsal commented on May 5, 2020

      @pablogsal
      Member

      New changeset 96074de by Pablo Galindo in branch 'master':
      bpo-40523: Add pass-throughs for hash() and reversed() to weakref.proxy objects (GH-19946)
      96074de

    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

    No one assigned

      Labels

      3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions