@@ -705,6 +705,51 @@ tmp/m.py:7: error: Invalid index type "int" for "A"; expected type "str"
705
705
tmp/m.py:8: error: Invalid index type "int" for "A"; expected type "str"
706
706
707
707
708
+ [case testDivmod]
709
+ from typing import Tuple, Union, SupportsInt
710
+ _Decimal = Union[Decimal, int]
711
+ class Decimal(SupportsInt):
712
+ def __init__(self, int) -> None: ...
713
+ def __divmod__(self, other: _Decimal) -> Tuple[Decimal, Decimal]: ...
714
+ def __rdivmod__(self, other: _Decimal) -> Tuple[Decimal, Decimal]: ...
715
+
716
+ i = 8
717
+ f = 8.0
718
+ d = Decimal(8)
719
+
720
+ reveal_type(divmod(i, i)) # E: Revealed type is 'Tuple[builtins.int, builtins.int]'
721
+ reveal_type(divmod(f, i)) # E: Revealed type is 'Tuple[builtins.float, builtins.float]'
722
+ reveal_type(divmod(d, i)) # E: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]'
723
+
724
+ reveal_type(divmod(i, f)) # E: Revealed type is 'Tuple[builtins.float, builtins.float]'
725
+ reveal_type(divmod(f, f)) # E: Revealed type is 'Tuple[builtins.float, builtins.float]'
726
+ divmod(d, f) # E: Unsupported operand types for divmod ("Decimal" and "float")
727
+
728
+ reveal_type(divmod(i, d)) # E: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]'
729
+ divmod(f, d) # E: Unsupported operand types for divmod ("float" and "Decimal")
730
+ reveal_type(divmod(d, d)) # E: Revealed type is 'Tuple[__main__.Decimal, __main__.Decimal]'
731
+
732
+ # Now some bad calls
733
+ divmod() # E: 'divmod' expects 2 arguments \
734
+ # E: Too few arguments for "divmod"
735
+ divmod(7) # E: 'divmod' expects 2 arguments \
736
+ # E: Too few arguments for "divmod"
737
+ divmod(7, 8, 9) # E: 'divmod' expects 2 arguments \
738
+ # E: Too many arguments for "divmod"
739
+ divmod(_x=7, _y=9) # E: 'divmod' must be called with 2 positional arguments
740
+
741
+ divmod('foo', 'foo') # E: Unsupported left operand type for divmod ("str")
742
+ divmod(i, 'foo') # E: Unsupported operand types for divmod ("int" and "str")
743
+ divmod(f, 'foo') # E: Unsupported operand types for divmod ("float" and "str")
744
+ divmod(d, 'foo') # E: Unsupported operand types for divmod ("Decimal" and "str")
745
+
746
+ divmod('foo', i) # E: Unsupported operand types for divmod ("str" and "int")
747
+ divmod('foo', f) # E: Unsupported operand types for divmod ("str" and "float")
748
+ divmod('foo', d) # E: Unsupported operand types for divmod ("str" and "Decimal")
749
+
750
+ [builtins fixtures/divmod.pyi]
751
+
752
+
708
753
-- Unary operators
709
754
-- ---------------
710
755
0 commit comments