reportOperatorIssue.md

April 8, 2026 · View on GitHub

Overview

reportOperatorIssue is a Pylance and Pyright diagnostic that identifies problems with the use of Python operators (such as +, -, *, /, etc.) where the operands are not type-compatible or where operator overloading is misapplied. This helps catch subtle bugs and type errors in code that uses custom classes or generics with operator methods.

Representative Issues

  • #7548: Always ensure that TypeVars are properly scoped and resolved within their respective contexts to avoid type resolution failures.

Examples

"hello" - "world"  # Error: Operator "-" not supported for types "str" and "str"

[1, 2] + (3, 4)   # Error: Operator "+" not supported for types "list[int]"
                  #   and "tuple[int, int]"

Fix — use compatible types:

10 - 3              # OK: both are int
[1, 2] + [3, 4]     # OK: both are list[int]

Fix — implement dunder methods for custom classes:

class Vector:
    def __init__(self, x: float, y: float):
        self.x = x
        self.y = y

    def __add__(self, other: "Vector") -> "Vector":
        return Vector(self.x + other.x, self.y + other.y)

Common Fixes & Workarounds

  1. Check that both operands of an operator are of compatible types or implement the appropriate dunder methods (e.g., __add__, __mul__).
  2. For generic classes, ensure that TypeVars are correctly scoped and resolved in all contexts where operators are used.
  3. If using operator overloading, verify that the method signatures match expected types and return values.
  4. Review the Pyright configuration documentation for options to adjust or suppress this diagnostic if needed.

See Also