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

Constructors of weakref mapping classes don't accept "self" and "dict" keyword arguments #67147

Closed
serhiy-storchaka opened this issue Nov 27, 2014 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 22958
Nosy @freddrake, @rhettinger, @pitrou, @benjaminp, @serhiy-storchaka
Dependencies
  • bpo-22609: Constructors of some mapping classes don't accept self keyword argument
  • Files
  • WeakValueDictionary_pos_only_params.patch
  • 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 2015-09-29.21:00:08.017>
    created_at = <Date 2014-11-27.16:13:23.539>
    labels = ['type-bug', 'library']
    title = 'Constructors of weakref mapping classes don\'t accept "self" and "dict" keyword arguments'
    updated_at = <Date 2015-09-29.21:00:08.016>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-09-29.21:00:08.016>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-09-29.21:00:08.017>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-11-27.16:13:23.539>
    creator = 'serhiy.storchaka'
    dependencies = ['22609']
    files = ['37395']
    hgrepos = []
    issue_num = 22958
    keywords = ['patch', 'needs review']
    message_count = 4.0
    messages = ['231767', '232358', '238694', '251885']
    nosy_count = 6.0
    nosy_names = ['fdrake', 'rhettinger', 'pitrou', 'benjamin.peterson', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22958'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    Dict-like types in the weakref module (WeakValueDictionary and WeakKeyDictionary) don't allow to specify key-value pair as keyword arguments if key is "self" or "dict".

    >>> import weakref
    >>> class A: pass
    ... 
    >>> a = A()
    >>> d = weakref.WeakValueDictionary(spam=a)
    >>> list(d.items())
    [('spam', <__main__.A object at 0xb6f3f88c>)]
    >>> weakref.WeakValueDictionary(self=a)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: __init__() got multiple values for argument 'self'
    >>> weakref.WeakValueDictionary(dict=a)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/serhiy/py/cpython/Lib/weakref.py", line 114, in __init__
        self.update(*args, **kw)
      File "/home/serhiy/py/cpython/Lib/weakref.py", line 261, in update
        dict = type({})(dict)
    TypeError: 'A' object is not iterable
    >>> d = weakref.WeakValueDictionary()
    >>> d.update(spam=a)
    >>> list(d.items())
    [('spam', <__main__.A object at 0xb6f3f88c>)]
    >>> d.update(self=a)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: update() got multiple values for argument 'self'
    >>> d.update(dict=a)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/serhiy/py/cpython/Lib/weakref.py", line 261, in update
        dict = type({})(dict)
    TypeError: 'A' object is not iterable

    Related issue for the collections module is bpo-22609. I think weakref mapping classes should be fixed in the same manner.

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 27, 2014
    @serhiy-storchaka
    Copy link
    Member Author

    Here is a patch similar to patch from bpo-22609 which makes WeakValueDictionary constructor and update accept keyword arguments "self" and "dict".

    @benjaminp
    Copy link
    Contributor

    lgtm

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 29, 2015

    New changeset 8274fc521e69 by Serhiy Storchaka in branch '2.7':
    Issue bpo-22958: Constructor and update method of weakref.WeakValueDictionary
    https://hg.python.org/cpython/rev/8274fc521e69

    New changeset 01c79072d671 by Serhiy Storchaka in branch '3.4':
    Issue bpo-22958: Constructor and update method of weakref.WeakValueDictionary
    https://hg.python.org/cpython/rev/01c79072d671

    New changeset 73b6b88ac28a by Serhiy Storchaka in branch '3.5':
    Issue bpo-22958: Constructor and update method of weakref.WeakValueDictionary
    https://hg.python.org/cpython/rev/73b6b88ac28a

    New changeset 815bb6a2d69e by Serhiy Storchaka in branch 'default':
    Issue bpo-22958: Constructor and update method of weakref.WeakValueDictionary
    https://hg.python.org/cpython/rev/815bb6a2d69e

    @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
    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