Skip to content

__iadd__ doesn't work when going through a Dict or List #2046

@euresti

Description

@euresti

class A(object):
    def __init__(self):
        self.a = 0

    def __iadd__(self, a):
        # type: (int) -> A
        self.a += 1
        return self

a = A()
a += 1

b = {0: a}
b[0] += 1

c = [a]
c[0] += 1

print(a.a)

Yields the following errors:

rt1.py:15: error: Incompatible types in assignment (expression has type "int", target has type "A")
rt1.py:18: error: No overload variant of "__setitem__" of "list" matches argument types [builtins.int, builtins.int]

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