Skip to content

Augmented assignment on asymmetric property uses setter type to resolve __iadd__ #22273

Open

Description

@mm21

Bug Report

For an augmented assignment like obj.prop += x on a property whose setter type differs from its getter type, mypy picks and checks the in-place operator using the setter type instead of the getter type.

At runtime, obj.prop += x does:

tmp = obj.prop             # getter -> G
tmp = tmp.__iadd__(x)      # G.__iadd__ (or G.__add__ if there is no __iadd__)
obj.prop = tmp             # setter: result must be assignable to the setter type S

mypy instead looks up __iadd__ on S and calls S's __iadd__. This causes false positives when S has no __iadd__ but G does (for example, when S is a union). Descriptors whose __set__ value type differs from their __get__ return type have the same problem.

To Reproduce

from collections.abc import Iterable


class P:
    def __iadd__(self, x: int | Iterable[int]) -> "P":
        return self


class N:
    @property
    def a(self) -> P:
        return P()

    @a.setter
    def a(self, v: P) -> None: ...

    @property
    def b(self) -> P:
        return P()

    @b.setter
    def b(self, v: P | list[int]) -> None: ...


n = N()
n.a += 1  # OK
n.b += 1  # false positive

Expected Behavior

No errors. P.__iadd__(1) returns P, and P is assignable to P | list[int].

Actual Behavior

main.py:27: error: Unsupported operand types for + ("P" and "int")  [operator]
main.py:27: error: Incompatible types in assignment (expression has type "int", variable has type "P | list[int]")  [assignment]

Your Environment

  • Mypy version used: 1.20.2; also reproduced on master (0cdcbfd)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13.7

Activity

  1. added
    bugmypy got something wrong
    on Oct 22, 2026
  2. added a commit that references this issue on Oct 22, 2026
    2947dcd
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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions