`divmod` still not working right
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
The changes to `divmod` in pyright 1.1.405 fixed the issue reported in #10849 . But here is a new issue where `pyright` is not handling `divmod` correctly and `mypy` does:
**Code or Screenshots**
PYI file: `divmod2.pyi`
```python
from typing import overload
class LHS:
@overload
def __divmod__(self, other: RHS) -> tuple[RHS, RHS]: ... # type: ignore[overload-overlap]
@overload
def __divmod__(self, other: object) -> tuple[LHS, LHS]: ...
class RHS:
pass
```
python file: `divmodtst2.py`
```python
from divmod2 import LHS, RHS
lhs = LHS()
rhs = RHS()
reveal_type(divmod(lhs, rhs))
reveal_type(divmod(lhs, 1))
```
pyright 1.1.405 reports on the last call to `divmod`:
```text
divmodtst2.py:7:13 - error: No overloads for "divmod" match the provided arguments (reportCallIssue)
divmodtst2.py:7:13 - information: Type of "divmod(lhs, 1)" is "Unknown"
divmodtst2.py:7:25 - error: Argument of type "Literal[1]" cannot be assigned to parameter "y" of type "SupportsRDivMod[_T_contra@divmod, _T_co@divmod]" in function "divmod"
"Literal[1]" is incompatible with protocol "SupportsRDivMod[LHS, _T_co@divmod]"
"__rdivmod__" is an incompatible type
Type "(value: int, /) -> tuple[int, int]" is not assignable to type "(other: _T_contra@SupportsRDivMod, /) -> _T_co@SupportsRDivMod"
Parameter 1: type "_T_contra@SupportsRDivMod" is incompatible with type "int"
"LHS" is not assignable to "int" (reportArgumentType)
```
I would have expected the second overload with `other: object` to match. Note that `lhs.__divmod__(1)` does not report an error and gives the correct type.
**VS Code extension or command-line**
pyright 1.1.405
Contributor guide
Research direction
Reproduce the report with divmod2.pyi and divmodtst2.py, then trace how pyright resolves the built-in divmod overloads versus the direct LHS.__divmod__(1) call. Done means the second divmod call is accepted and its inferred type matches the expected tuple type without the reported errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100