Skip to content

Commit 4a2e333

Browse files
committed
Type Tree.__rtruediv__ as uncallable in the stub
The stub declared __rtruediv__(other: str) -> Tree | Blob, so mypy accepted "x / tree" even though reflected tree division always raises TypeError at runtime: CPython synthesizes the wrapper from the single nb_true_divide slot with the operands swapped, and Tree_divide returns NotImplemented for a non-Tree left operand (issue #1505). Declare it (self, other: Never, /) -> NotImplementedType instead, the closest approximation of the real behavior: no argument is acceptable, and the wrapper only ever returns NotImplemented. Also fix the stale config path in the mypy-stubtest.ini usage comment. Assisted-by: Kimi (Kimi Code)
1 parent 01c1743 commit 4a2e333

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎mypy-stubtest.ini‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# (tool shipped with mypy).
33
#
44
# Run "build.sh stubtest", or:
5-
# stubtest --mypy-config-file test/mypy-stubtest.ini pygit2._pygit2
5+
# stubtest --mypy-config-file mypy-stubtest.ini pygit2._pygit2
66
#
77
# Format info:
88
# https://mypy.readthedocs.io/en/stable/config_file.html

‎pygit2/_pygit2.pyi‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ from io import DEFAULT_BUFFER_SIZE, IOBase
33
from pathlib import Path
44
from queue import Queue
55
from threading import Event
6+
from types import NotImplementedType
67
from typing import ( # noqa: UP035
78
Generic,
89
Literal,
10+
Never,
911
Optional,
1012
Type,
1113
TypedDict,
@@ -844,7 +846,7 @@ class Tree(Object):
844846
def __getitem__(self, index: str | int, /) -> Tree | Blob: ... # Tree_subscript
845847
def __iter__(self) -> Iterator[Object]: ...
846848
def __len__(self) -> int: ... # Tree_len
847-
def __rtruediv__(self, other: str, /) -> Tree | Blob: ...
849+
def __rtruediv__(self, other: Never, /) -> NotImplementedType: ...
848850
def __truediv__(self, other: str, /) -> Tree | Blob: ... # Tree_divide
849851

850852
@disjoint_base

0 commit comments

Comments
 (0)