Skip to content

Nested generator in dictionary view misbehaves after unpacking and parameter packing #126875

@WH-2099

Description

@WH-2099

Bug report

Bug description:

mapping = {
    1: [101, 102, 103],
    2: [201, 202, 203],
    3: [301, 302, 303],
}

def iterate_generator(gen):
    for pairs in gen:
        print(", ".join(str(x) for x in pairs))

def iterate_packing_unpacking(*args):
    for pairs in args:
        print(", ".join(str(x) for x in pairs))

iterate_generator(
    (((x, x_member) for x_member in x_members) for x, x_members in mapping.items())
)
# (1, 101), (1, 102), (1, 103)
# (2, 201), (2, 202), (2, 203)
# (3, 301), (3, 302), (3, 303)

iterate_packing_unpacking(
    *(((x, x_member) for x_member in x_members) for x, x_members in mapping.items())
)
# (3, 101), (3, 102), (3, 103)
# (3, 201), (3, 202), (3, 203)
# (3, 301), (3, 302), (3, 303)

Expectation

The output of iterate_packing_unpacking should be the same as iterate_generator.

CPython versions and Operating systems tested on:

  • 3.13
    • Linux
    • macOS
    • Windows
  • 3.12
    • Linux
    • macOS
    • Windows
  • 3.11
    • Linux
    • macOS
    • Windows
  • 3.10
    • Linux
    • macOS
    • Windows
  • 3.9
    • Linux
    • macOS
    • Windows

tested on:

Linux, macOS, Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions