Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypyc/test-data/fixtures/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __add__(self, value: List[_S], /) -> List[_S | _T]: ...
def __iadd__(self, value: Iterable[_T], /) -> List[_T]: ... # type: ignore[misc]
def append(self, x: _T) -> None: pass
def pop(self, i: int = -1) -> _T: pass
def count(self, _T) -> int: pass
def count(self, x: _T) -> int: pass
def extend(self, l: Iterable[_T]) -> None: pass
def insert(self, i: int, x: _T) -> None: pass
def sort(self) -> None: pass
Expand Down Expand Up @@ -365,7 +365,7 @@ def reversed(object: Sequence[_T]) -> Iterator[_T]: ...
def id(o: object) -> int: pass
# This type is obviously wrong but the test stubs don't have Sized anymore
def len(o: object) -> int: pass
def print(*object) -> None: pass
def print(*args: object) -> None: pass
def isinstance(x: object, t: object) -> bool: pass
def iter(i: Iterable[_T]) -> Iterator[_T]: pass
@overload
Expand Down
6 changes: 3 additions & 3 deletions mypyc/test-data/fixtures/typing-full.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ from abc import abstractmethod, ABCMeta
class GenericMeta(type): pass

class _SpecialForm:
def __getitem__(self, index): ...
def __getitem__(self, index: Any) -> Any: ...
class TypeVar:
def __init__(self, name, *args, bound=None): ...
def __or__(self, other): ...
def __init__(self, name: str, *args: Any, bound: Any = None): ...
def __or__(self, other: Any) -> Any: ...

cast = 0
overload = 0
Expand Down
48 changes: 35 additions & 13 deletions mypyc/test-data/run-dunders.test
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class SeqError:
def __contains__(self, x: int) -> bool:
raise RuntimeError()

def __len__(self):
def __len__(self) -> int:
return -5

def any_seq_error() -> Any:
Expand Down Expand Up @@ -545,6 +545,7 @@ def test_type_mismatch_fall_back_to_reverse() -> None:
assert F()**G() == -6

[case testDundersBinaryNotImplemented]
# mypy: allow-untyped-defs
from typing import Any, Union
from testutil import assertRaises

Expand Down Expand Up @@ -617,15 +618,28 @@ def test_unannotated_add() -> None:
with assertRaises(TypeError, "unsupported operand type(s) for +: 'F' and 'str'"):
o + 'x'

o2: Any = F(4)
assert o2 + 5 == 9
with assertRaises(TypeError, "unsupported operand type(s) for +: 'F' and 'str'"):
o2 + 'x'

def test_unannotated_add_and_radd_1() -> None:
o = F(4)
assert o + G() == 5

o2: Any = F(4)
assert o2 + G() == 5

def test_unannotated_radd() -> None:
assert 'x' + G() == 'a'
with assertRaises(TypeError, "unsupported operand type(s) for +: 'int' and 'G'"):
1 + G()

o: Any = G()
assert 'x' + o == 'a'
with assertRaises(TypeError, "unsupported operand type(s) for +: 'int' and 'G'"):
1 + o

class H:
def __add__(self, x):
if isinstance(x, int):
Expand All @@ -644,40 +658,48 @@ def test_unannotated_add_and_radd_2() -> None:
with assertRaises(TypeError, "unsupported operand type(s) for +: 'int' and 'H'"):
1 + h

h2: Any = H()
assert h + 5 == 6
assert 'x' + h == 22
with assertRaises(TypeError, "unsupported operand type(s) for +: 'int' and 'H'"):
1 + h

# TODO: Inheritance

[case testDifferentReverseDunders]
from typing import Any

class C:
# __radd__ and __rsub__ are tested elsewhere

def __rmul__(self, x):
def __rmul__(self, x: Any) -> int:
return 1

def __rtruediv__(self, x):
def __rtruediv__(self, x: Any) -> int:
return 2

def __rmod__(self, x):
def __rmod__(self, x: Any) -> int:
return 3

def __rfloordiv__(self, x):
def __rfloordiv__(self, x: Any) -> int:
return 4

def __rlshift__(self, x):
def __rlshift__(self, x: Any) -> int:
return 5

def __rrshift__(self, x):
def __rrshift__(self, x: Any) -> int:
return 6

def __rand__(self, x):
def __rand__(self, x: Any) -> int:
return 7

def __ror__(self, x):
def __ror__(self, x: Any) -> int:
return 8

def __rxor__(self, x):
def __rxor__(self, x: Any) -> int:
return 9

def __rmatmul__(self, x):
def __rmatmul__(self, x: Any) -> int:
return 10

def test_reverse_dunders() -> None:
Expand Down Expand Up @@ -803,10 +825,10 @@ def test_error() -> None:
c += 'x'

class BadInplaceAdd:
def __init__(self):
def __init__(self) -> None:
self.x = 0

def __iadd__(self, x):
def __iadd__(self, x: int) -> Any:
self.x += x

def test_in_place_operator_returns_none() -> None:
Expand Down
Loading
Loading