@@ -46,22 +46,25 @@ assert_type(m_td % m_td, np.timedelta64[dt.timedelta | None])
4646assert_type (AR_m % m , _nt .Array [np .timedelta64 ])
4747assert_type (m % AR_m , _nt .Array [np .timedelta64 ])
4848
49- # NOTE: `builtins.divmod` cannot be used because of
50- # https://github.com/microsoft/pyright/issues/9896
51-
52- assert_type (divmod (m , m ), tuple [np .int64 , np .timedelta64 ])
53- assert_type (m .__divmod__ (m_nat ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
54- assert_type (m .__divmod__ (m_int0 ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
55- assert_type (m .__divmod__ (m_int ), tuple [np .int64 , np .timedelta64 [int | None ]]) # noqa: PLC2801
56- assert_type (m_nat .__divmod__ (m ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
57- assert_type (m_int .__divmod__ (m_nat ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
58- assert_type (m_int .__divmod__ (m_int0 ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
59- assert_type (m_int .__divmod__ (m_int ), tuple [np .int64 , np .timedelta64 [int | None ]]) # noqa: PLC2801
60- assert_type (m_int .__divmod__ (m_td ), tuple [np .int64 , np .timedelta64 [int | None ]]) # noqa: PLC2801
61- assert_type (m_td .__divmod__ (m_nat ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
62- assert_type (m_td .__divmod__ (m_int0 ), tuple [np .int64 , np .timedelta64 [None ]]) # noqa: PLC2801
63- assert_type (m_td .__divmod__ (m_int ), tuple [np .int64 , np .timedelta64 [int | None ]]) # noqa: PLC2801
64- assert_type (m_td .__divmod__ (m_td ), tuple [np .int64 , np .timedelta64 [dt .timedelta | None ]]) # noqa: PLC2801
49+ # NOTE: The pyright ignores are the consequence of a pernicious bug in pyright
50+ # (microsoft/pyright#9896, microsoft/pyright#10849, microsoft/pyright#10899) that
51+ # causes incorrect behavior in certain functions that accept generic protocols with
52+ # overloaded methods. Even though mypy also isn't fully correct here, it will at least
53+ # not falsely reject valid calls, and has no problems with any of the following tests.
54+
55+ assert_type (divmod (m , m ), tuple [np .int64 , np .timedelta64 ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
56+ assert_type (divmod (m , m_nat ), tuple [np .int64 , np .timedelta64 [None ]])
57+ assert_type (divmod (m , m_int0 ), tuple [np .int64 , np .timedelta64 [None ]])
58+ assert_type (divmod (m , m_int ), tuple [np .int64 , np .timedelta64 [int | None ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
59+ assert_type (divmod (m_nat , m ), tuple [np .int64 , np .timedelta64 [None ]])
60+ assert_type (divmod (m_int , m_nat ), tuple [np .int64 , np .timedelta64 [None ]])
61+ assert_type (divmod (m_int , m_int0 ), tuple [np .int64 , np .timedelta64 [None ]])
62+ assert_type (divmod (m_int , m_int ), tuple [np .int64 , np .timedelta64 [int | None ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
63+ assert_type (divmod (m_int , m_td ), tuple [np .int64 , np .timedelta64 [int | None ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
64+ assert_type (divmod (m_td , m_nat ), tuple [np .int64 , np .timedelta64 [None ]])
65+ assert_type (divmod (m_td , m_int0 ), tuple [np .int64 , np .timedelta64 [None ]])
66+ assert_type (divmod (m_td , m_int ), tuple [np .int64 , np .timedelta64 [int | None ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
67+ assert_type (divmod (m_td , m_td ), tuple [np .int64 , np .timedelta64 [dt .timedelta | None ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
6568
6669assert_type (divmod (AR_m , m ), tuple [_nt .Array [np .int64 ], _nt .Array [np .timedelta64 ]])
6770assert_type (divmod (m , AR_m ), tuple [_nt .Array [np .int64 ], _nt .Array [np .timedelta64 ]])
@@ -78,8 +81,8 @@ assert_type(b_ % AR_b, _nt.Array[np.int8])
7881
7982assert_type (divmod (b_ , b_ ), tuple [np .int8 , np .int8 ])
8083assert_type (divmod (b_ , b ), tuple [np .int8 , np .int8 ])
81- assert_type (divmod (b_ , i ), tuple [np .intp , np .intp ])
82- assert_type (divmod (b_ , f ), tuple [np .float64 , np .float64 ])
84+ assert_type (divmod (b_ , i ), tuple [np .intp , np .intp ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
85+ assert_type (divmod (b_ , f ), tuple [np .float64 , np .float64 ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
8386assert_type (divmod (b_ , i8 ), tuple [np .int64 , np .int64 ])
8487assert_type (divmod (b_ , u8 ), tuple [np .uint64 , np .uint64 ])
8588assert_type (divmod (b_ , f8 ), tuple [np .float64 , np .float64 ])
@@ -95,8 +98,8 @@ assert_type(f8 % b_, np.float64)
9598assert_type (AR_b % b_ , _nt .Array [np .int8 ])
9699
97100assert_type (divmod (b_ , b ), tuple [np .int8 , np .int8 ])
98- assert_type (divmod (b_ , i ), tuple [np .intp , np .intp ])
99- assert_type (divmod (b_ , f ), tuple [np .float64 , np .float64 ])
101+ assert_type (divmod (b_ , i ), tuple [np .intp , np .intp ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
102+ assert_type (divmod (b_ , f ), tuple [np .float64 , np .float64 ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
100103assert_type (divmod (b_ , i8 ), tuple [np .int64 , np .int64 ])
101104assert_type (divmod (b_ , u8 ), tuple [np .uint64 , np .uint64 ])
102105assert_type (divmod (b_ , f8 ), tuple [np .float64 , np .float64 ])
@@ -117,7 +120,7 @@ assert_type(i8 % AR_b, _nt.Array[np.int64])
117120
118121assert_type (divmod (i8 , b ), tuple [np .int64 , np .int64 ])
119122assert_type (divmod (i8 , i ), tuple [np .int64 , np .int64 ])
120- assert_type (divmod (i8 , f ), tuple [np .float64 , np .float64 ])
123+ assert_type (divmod (i8 , f ), tuple [np .float64 , np .float64 ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
121124assert_type (divmod (i8 , i4 ), tuple [np .int64 , np .int64 ])
122125assert_type (divmod (i8 , i8 ), tuple [np .int64 , np .int64 ])
123126assert_type (divmod (i8 , f8 ), tuple [np .float64 , np .float64 ])
@@ -136,14 +139,14 @@ assert_type(f4 % i4, np.float64)
136139assert_type (AR_b % i8 , _nt .Array [np .int64 ])
137140
138141assert_type (divmod (i8 , b ), tuple [np .int64 , np .int64 ])
139- assert_type (divmod (i8 , f ), tuple [np .float64 , np .float64 ])
142+ assert_type (divmod (i8 , f ), tuple [np .float64 , np .float64 ]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
140143assert_type (divmod (i8 , i8 ), tuple [np .int64 , np .int64 ])
141144assert_type (divmod (i8 , f8 ), tuple [np .float64 , np .float64 ])
142145assert_type (divmod (i8 , i4 ), tuple [np .int64 , np .int64 ])
143146assert_type (divmod (i4 , i8 ), tuple [np .int64 , np .int64 ])
144147assert_type (divmod (f4 , i8 ), tuple [np .float64 , np .float64 ])
145148assert_type (divmod (f4 , i4 ), tuple [np .float64 , np .float64 ])
146- assert_type (divmod (AR_b , i8 ), tuple [_nt .Array [np .int64 ], _nt .Array [np .int64 ]])
149+ assert_type (divmod (AR_b , i8 ), tuple [_nt .Array [np .int64 ], _nt .Array [np .int64 ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
147150
148151# float
149152
@@ -161,7 +164,7 @@ assert_type(divmod(f4, f4), tuple[np.float32, np.float32])
161164assert_type (divmod (f8 , AR_b ), tuple [_nt .Array [np .float64 ], _nt .Array [np .float64 ]])
162165
163166assert_type (b % f8 , np .float64 )
164- assert_type (f % f8 , np .float64 ) # pyright: ignore[reportAssertTypeFailure] # pyright incorrectly infers `builtins. float`
167+ assert_type (f % f8 , np .float64 ) # pyright: ignore[reportAssertTypeFailure] # pyright incorrectly infers `float`
165168assert_type (f8 % f8 , np .float64 )
166169assert_type (f8 % f8 , np .float64 )
167170assert_type (f4 % f4 , np .float32 )
@@ -170,6 +173,6 @@ assert_type(AR_b % f8, _nt.Array[np.float64])
170173assert_type (divmod (b , f8 ), tuple [np .float64 , np .float64 ])
171174assert_type (divmod (f8 , f8 ), tuple [np .float64 , np .float64 ])
172175assert_type (divmod (f4 , f4 ), tuple [np .float32 , np .float32 ])
173- assert_type (divmod (f , f8 ), tuple [np .float64 , np .float64 ]) # pyright: ignore[reportAssertTypeFailure]
176+ assert_type (divmod (f , f8 ), tuple [np .float64 , np .float64 ]) # pyright: ignore[reportAssertTypeFailure] # pyright incorrectly infers `tuple[float, float]`
174177assert_type (divmod (f4 , f8 ), tuple [np .float64 , np .float64 ])
175- assert_type (divmod (AR_b , f8 ), tuple [_nt .Array [np .float64 ], _nt .Array [np .float64 ]])
178+ assert_type (divmod (AR_b , f8 ), tuple [_nt .Array [np .float64 ], _nt .Array [np .float64 ]]) # pyright: ignore[reportArgumentType, reportAssertTypeFailure, reportCallIssue]
0 commit comments