Skip to content

__reversed__ signature ignored when using reversed and enumerate? #3048

@MarcoGorelli

Description

@MarcoGorelli

Describe the Bug

from __future__ import annotations

from collections.abc import Iterable, Iterator
from typing import reveal_type, Sequence


class Series: ...

class DataFrame:
    def __iter__(self) -> Iterator[Series]: ...
    def __reversed__(self) -> Iterator[Series]: ...
    def __len__(self) -> int: ...
    def __getitem__(self, key: int | Sequence[int]) -> Series | DataFrame: ...

def func(s: Series) -> None:
    ...

def main(a: DataFrame) -> None:
    for i, s in enumerate(reversed(a)):
        func(s)

outputs

(scratch) marcogorelli@DESKTOP-U8OKFP3:~/scratch$ pyrefly check t.py
ERROR Argument `DataFrame | Series` is not assignable to parameter `s` with type `Series` in function `func` [bad-argument-type]
  --> t.py:20:14
   |
20 |         func(s)
   |              ^
   |
 INFO 1 error

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEA%2Bg2AK4AuLlMTdENxuSmzoZ0uNqjYRc6OAB10CsNXoBjXFFiqpMuIVTZVvfoOEBJNjEoHYAGjoWrkwUpV02pYhHQBzYwKE6LgA3GFQoBg9iGHsAZRgARxYYdFUYBQzUqFQ4ODp4ygh4RDpCMszVbNy6ABFJVAAxaxoYRAU6DrpMGDBGBghLSiYACjgYKDAASjoAWgA%2BB0HnSgBtAqK4AF0SssJ2zu7ephCrMcwRsYnp%2BcWnNkE1qw3t0vL0Tq6evth0C-Gp2YLbxsHZvD6HPo%2BGBSSw0P4TewAaxgpBKwLoAB98olkqkYCtgZtrgt1vBMbV6k1UC1QXtFFgvqxUqMSqS4MS6AA5GStfYdXaZCE0VDeYaoEp1CRUloc7noXnvTpgQS8ex5bx0FIsFrWSzDE6UM5iyaTNqKj4dJmqUaTTIgWwgMhcMBQUiEe40KAUADEdAACqRna66GgsHh8HR1OhID5OJJpOg6b74jA6AALNhsYhwRAAelzTp6rsIgh8uZSucwuFUcFzUZjcZ06FzdGVlBEwRF2WwsEjMgbuoTdFwxCbegUZDYaZkM1ChqHAF46HIQABmQgARgATCuFCsrNRDZsFCx0HwApZMDNMBAuNoIKE6EuAOQQHxiLjPhRiNgzLhJW8YCvZFSBmVBVDSaoXwAd1QSh0C-dAQAAXwdcCpFCBpoBgChQxwAgSHIZCgA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions