Fix overloads with a generic self: dropped when matching a Protocol#3975
Fix overloads with a generic self: dropped when matching a Protocol#3975jorenham wants to merge 1 commit into
self: dropped when matching a Protocol#3975Conversation
|
Diff from mypy_primer, showing the effect of this PR on open source code: jax (https://github.com/google/jax)
+ ERROR jax/_src/lax/linalg.py:1066:74-78: Argument `list[signedinteger[_32Bit]]` is not assignable to parameter `broadcast_dimensions` with type `Sequence[int]` in function `jax._src.lax.lax.broadcast_in_dim` [bad-argument-type]
+ ERROR jax/_src/lax/linalg.py:1068:63-67: Argument `list[signedinteger[_32Bit]]` is not assignable to parameter `broadcast_dimensions` with type `Sequence[int]` in function `jax._src.lax.lax.broadcast_in_dim` [bad-argument-type]
scipy-stubs (https://github.com/scipy/scipy-stubs)
+ ERROR tests/sparse/test_csr.pyi:196:1-2: Unused `# pyrefly: ignore` comment for code(s): assert-type [unused-ignore]
DateType (https://github.com/glyph/DateType)
- ERROR src/datetype/test/test_datetype.py:49:38-54: `Time[None]` is not assignable to `NaiveTime` [bad-assignment]
colour (https://github.com/colour-science/colour)
- ERROR colour/temperature/cie_d.py:113:21-118:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[Any], **dict[str, str | dict[str, float]]) [no-matching-overload]
+ ERROR colour/temperature/cie_d.py:113:21-118:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]], **dict[str, str | dict[str, float]]) [no-matching-overload]
- ERROR colour/temperature/hernandez1999.py:176:21-181:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=Unknown, args=tuple[Any], **dict[str, str | dict[str, float]]) [no-matching-overload]
+ ERROR colour/temperature/hernandez1999.py:176:21-181:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=Unknown, args=tuple[ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]], **dict[str, str | dict[str, float]]) [no-matching-overload]
- ERROR colour/temperature/kang2002.py:112:21-117:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[Any], **dict[str, str | dict[str, float]]) [no-matching-overload]
+ ERROR colour/temperature/kang2002.py:112:21-117:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]], **dict[str, str | dict[str, float]]) [no-matching-overload]
- ERROR colour/temperature/krystek1985.py:117:21-122:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], uv: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[Any], **dict[str, str | dict[str, float]]) [no-matching-overload]
+ ERROR colour/temperature/krystek1985.py:117:21-122:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], uv: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]], **dict[str, str | dict[str, float]]) [no-matching-overload]
- ERROR colour/temperature/mccamy1992.py:160:21-165:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=Unknown, args=tuple[Any], **dict[str, str | dict[str, float]]) [no-matching-overload]
+ ERROR colour/temperature/mccamy1992.py:160:21-165:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((xy: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=Unknown, args=tuple[ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]], **dict[str, str | dict[str, float]]) [no-matching-overload]
- ERROR colour/temperature/planck1900.py:120:21-125:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], uv: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[Any], **dict[str, str | dict[str, float]]) [no-matching-overload]
+ ERROR colour/temperature/planck1900.py:120:21-125:14: No matching overload found for function `scipy.optimize._minimize.minimize` called with arguments: ((CCT: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]], uv: ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]) -> DTypeFloat, x0=list[int], args=tuple[ndarray[tuple[Any, ...], dtype[float64 | floating[_16Bit] | floating[_32Bit]]]], **dict[str, str | dict[str, float]]) [no-matching-overload]
|
So all primer changes are good news. |
NathanTempest
left a comment
There was a problem hiding this comment.
Approving and thanks, @jorenham for the clean fix.
filter_overloads_by_self_type was matching the receiver against a self (still-unbound type params) so is_subset_eq compared against rigid unsolvable variables and silently dropped overloads that should apply. Substituting just those params with implicit Any before the applicability check is the right direction here.
Only the overload's own tparams are gradualized but the concrete parts of the self: are preserved The Any-substituted type is only used for the keep/drop decision; the surviving overload keeps its real self: Arr[S2, T2] -> Arr[S2, T2], which is then solved precisely against the receiver. So this increases precision rather than loosening it.
|
@NathanTempest has imported this pull request. If you are a Meta employee, you can view this in D111462642. |
Summary
filter_overloads_by_self_typedropped any overload whoseself:mentions the overload's own type params, sinceis_subset_eq(receiver, self)checks against a rigid, unsolvable variable. Substitute those params withAnyfirst, so the receiver is matched against a gradualself:.An overload whose
self:mentions its own type parameters is matched gradually by substituting those parameters withAny (self: Arr[S, T] -> Arr[Any, Any]), which is exact for the realistic single-occurrence case and only over-accepts the presumably niche degenerate repeated-parameter case,(self: C[Z, Z]), same as mypy and pyright.Fixes #3974
Test Plan
Regression tests added