Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
38 changes: 20 additions & 18 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 @@ -595,16 +595,16 @@ def test_any_radd() -> None:
assert d3 + e3 == 4

class F:
def __init__(self, v):
def __init__(self, v: Any):
self.v = v

def __add__(self, x):
def __add__(self, x: Any) -> Any:
if isinstance(x, int):
return self.v + x
return NotImplemented

class G:
def __radd__(self, x):
def __radd__(self, x: Any) -> Any:
if isinstance(x, F):
return x.v + 1
if isinstance(x, str):
Expand All @@ -627,12 +627,12 @@ def test_unannotated_radd() -> None:
1 + G()

class H:
def __add__(self, x):
def __add__(self, x: Any) -> Any:
if isinstance(x, int):
return x + 1
return NotImplemented

def __radd__(self, x):
def __radd__(self, x: Any) -> Any:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, these are part of a case that seems to be explicitly testing unannotated behavior ("test_unannotated_add_and_radd_2") -- does annotating these with Any affect that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidentally, I actually started a similar patch where I worked around cases like this by adding support for # flags: --allow-untyped-defs in the run tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the annotations in this test case. Annotating with Any should have only the effect of turning on type checking and type inference in the function body.

if isinstance(x, str):
return 22
return NotImplemented
Expand All @@ -647,37 +647,39 @@ def test_unannotated_add_and_radd_2() -> None:
# 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 +805,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