Skip to content

operator.iconcat ignores list subclass __iadd__ override #158733

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: "Same as a += b, for a and b sequences." — supplied public API and iconcat docstring.

Expected: Return the fresh plain list [99], leaving both original operands unchanged.

Actual: Returns the fresh plain list [1, 2], leaving both original operands unchanged.

import operator

class L(list):
    def __iadd__(self, other):
        return [99]

a, ref, b, rb = L([1]), L([1]), [2], [2]
data = {"mode": "fresh99", "initial": list(a), "rhs": list(b)}

def snapshot(result, original, rhs):
    return {
        "result": list(result),
        "result_type": type(result).__name__,
        "original_after": list(original),
        "rhs_after": list(rhs),
        "result_is_original": result is original,
    }

if not (isinstance(a, list) and type(b) is list
        and type(a.__iadd__(b)) is list and a == [1] and b == [2]):
    print("REFUTATION REJECTED:", "input does not satisfy the claimed domain")
else:
    actual = snapshot(operator.iconcat(a, b), a, b)
    original = ref
    ref += rb
    expected = snapshot(ref, original, rb)
    if actual != expected:
        print("REFUTATION CONFIRMED:", data, actual, expected)
    else:
        print("REFUTATION REJECTED:", "iconcat agrees with independently executed +=")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library operator:

REFUTATION CONFIRMED: {'mode': 'fresh99', 'initial': [1], 'rhs': [2]} {'result': [1, 2], 'result_type': 'list', 'original_after': [1], 'rhs_after': [2], 'result_is_original': False} {'result': [99], 'result_type': 'list', 'original_after': [1], 'rhs_after': [2], 'result_is_original': False}

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/operator-20261003-044103-c1

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions