Skip to content

Mixed Type ChainMap Order Dependency #106261

Closed as not planned
Closed as not planned
@joegeisbauer

Description

@joegeisbauer

Bug report

A ChainMap will allow for mixed types without throwing an error; however, accessing values from the ChainMap via keys fails once it hits a list, if the desired key follows the list. In the example below, c will throw a TypeError with the following message: "TypeError: list indices must be integers or slices, not str," while d will return the correct value.

from collections import ChainMap

a = [0,1,2,3]
b = {'animal': 'dog', 'color': 'black'}
c = ChainMap(a,b)
d = ChainMap(b,a)
c['animal'] (throws error)
d['animal'] (outputs 'dog')

Your environment

  • CPython versions tested on: 3.10.6 and master repo branch
  • Operating system and architecture: Ubuntu 22.04 x86_64

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions