Skip to content

using += on types without __iadd__ will evaluate __getattr__ instead of __add__ #2248

@jorenham

Description

@jorenham

for a .pyi like

import pandas as pd

s: pd.Series[str]
s += "a"

, Pyrefly reports

`+=` is not supported between `Series[str]` and `Literal['a']`
  Expected `__iadd__` to be a callable, got `str`

This is accepted by mypy, pyright, basedpyright, and ty.

I'm guessing this has to do with there not being a Series.__iadd__ method in the stubs, causing Pyrefly to incorrectly prioritize Series.__getattr__ (which returns a str) over Series.__add__.

Used versions:

  • pyrefly==0.50.0
  • pandas==2.3.3
  • pandas-stubs==2.3.3.260113

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions