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

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

Closed
rhettinger opened this issue May 5, 2020 · 2 comments
Closed

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

rhettinger opened this issue May 5, 2020 · 2 comments
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

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']

    @rhettinger
    Copy link
    Contributor Author

    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')

    @rhettinger rhettinger added 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 5, 2020
    @pablogsal
    Copy link
    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

    @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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants