Skip to content

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

Closed

Description

@ap
mannequin
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']

    Activity

    1. ap commented on Nov 28, 2020

      apmannequin
      MannequinAuthor

      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'}
    2. added
      type-bugAn unexpected behavior, bug, or error
      stdlibStandard Library Python modules in the Lib/ directory
      on Nov 28, 2020
    3. 3 remaining items

    4. added
      performancePerformance or resource usage
      and removed
      type-bugAn unexpected behavior, bug, or error
      on Nov 28, 2020
    5. rhettinger commented on Nov 28, 2020

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

    6. self-assigned this
      on Nov 28, 2020
    7. self-assigned this
      on Nov 28, 2020
    8. rhettinger commented on Nov 30, 2020

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

    9. rhettinger commented on Nov 30, 2020

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

    10. 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

    Labels

    3.10 (EOL)end of life3.9 (EOL)end of lifeperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions