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

collections.ChainMap.__iter__ calls __getitem__ on underlying maps #86653

Closed
ap mannequin opened this issue Nov 28, 2020 · 4 comments
Closed

collections.ChainMap.__iter__ calls __getitem__ on underlying maps #86653

ap mannequin opened this issue Nov 28, 2020 · 4 comments
Assignees
Labels
3.9 only security fixes 3.10 only security fixes performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@ap
Copy link
Mannequin

ap mannequin commented Nov 28, 2020

BPO 42487
Nosy @rhettinger, @ambv, @serhiy-storchaka, @miss-islington, @ap--
PRs
  • bpo-42487: don't call __getitem__ of underlying maps in ChainMap.__iter__ #23534
  • [3.9] bpo-42487: don't call __getitem__ of underlying maps in ChainMap.__iter__ (GH-23534) #23569
  • 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/rhettinger'
    closed_at = <Date 2020-11-30.21:23:39.144>
    created_at = <Date 2020-11-28.00:50:30.644>
    labels = ['library', '3.9', '3.10', 'performance']
    title = 'collections.ChainMap.__iter__ calls __getitem__ on underlying maps'
    updated_at = <Date 2020-11-30.21:23:39.144>
    user = 'https://github.com/ap'

    bugs.python.org fields:

    activity = <Date 2020-11-30.21:23:39.144>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2020-11-30.21:23:39.144>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2020-11-28.00:50:30.644>
    creator = 'ap--'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42487
    keywords = ['patch']
    message_count = 4.0
    messages = ['381971', '381974', '382159', '382164']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'lukasz.langa', 'serhiy.storchaka', 'miss-islington', 'ap--']
    pr_nums = ['23534', '23569']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue42487'
    versions = ['Python 3.9', 'Python 3.10']

    @ap
    Copy link
    Mannequin Author

    ap mannequin commented Nov 28, 2020

    Hello,

    I encountered an issue with collections.ChainMap, that was introduced when https://bugs.python.org/issue32792 got fixed.

    Iterating a ChainMap will call __getitem__ on its underlying maps:

    >>> from collections import UserDict, ChainMap
    >>> class MyDict(UserDict):
    ...     def __getitem__(self, k):
    ...         print("expensive computation", k)
    ...         return super().__getitem__(k)
    ... 
    >>> set(ChainMap(MyDict(a=1, b=2, c=3)))
    expensive computation a
    expensive computation b
    expensive computation c
    {'c', 'b', 'a'}

    @ap ap mannequin added type-bug An unexpected behavior, bug, or error 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir labels Nov 28, 2020
    @rhettinger rhettinger added performance Performance or resource usage and removed 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Nov 28, 2020
    @rhettinger
    Copy link
    Contributor

    I had a discussion with the release manager and we're good to backport to 3.9 but not 3.8.

    Serhiy, would you also take a look at this?

    @rhettinger rhettinger added the 3.9 only security fixes label Nov 28, 2020
    @rhettinger rhettinger self-assigned this Nov 28, 2020
    @rhettinger rhettinger added the 3.9 only security fixes label Nov 28, 2020
    @rhettinger rhettinger self-assigned this Nov 28, 2020
    @rhettinger
    Copy link
    Contributor

    New changeset 0be9ce3 by Andreas Poehlmann in branch 'master':
    bpo-42487: don't call __getitem__ of underlying maps in ChainMap.__iter__ (GH-23534)
    0be9ce3

    @rhettinger
    Copy link
    Contributor

    New changeset cf22aa3 by Miss Islington (bot) in branch '3.9':
    bpo-42487: don't call __getitem__ of underlying maps in ChainMap.__iter__ (GH-23534) (GH-23569)
    cf22aa3

    @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.9 only security fixes 3.10 only security fixes performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant