Uh oh!
There was an error while loading. Please reload this page.
Avoid narrowing type[T] - #20662
Conversation
This relates to changes made in python#20492
This comment has been minimized.
This comment has been minimized.
hauntsaninja
commented
Jan 28, 2026
This is a win on spark and zulip So I think all the primer is good |
| reveal_type(x) # N: Revealed type is "Any" | ||
| [builtins fixtures/tuple.pyi] | ||
| [case testNarrowTypeObject] |
There was a problem hiding this comment.
The behaviour here was fixed in the first PR #20492 , not in this one, but I didn't add the test coverage for it in the original PR.
Makes sense to add in this PR because bad versions of the current change could have regressed the fix.
(The behaviour in the f3 case could potentially be made more consistent, but this should be the subject of future investigation)
Diff from mypy_primer, showing the effect of this PR on open source code: spark (https://github.com/apache/spark)
- python/pyspark/mllib/regression.py:282: error: Unused "type: ignore" comment [unused-ignore]- python/pyspark/mllib/regression.py:282: error: Incompatible return value type (got "LogisticRegressionModel", expected "LM") [return-value]- python/pyspark/mllib/regression.py:282: note: Error code "return-value" not covered by "type: ignore" comment
zulip (https://github.com/zulip/zulip)
- analytics/views/stats.py:577: error: Incompatible return value type (got "QuerySet[RealmCount, RealmCount]", expected "QuerySet[CountT, CountT]") [return-value]- analytics/views/stats.py:579: error: Incompatible return value type (got "QuerySet[UserCount, UserCount]", expected "QuerySet[CountT, CountT]") [return-value]- analytics/views/stats.py:581: error: Incompatible return value type (got "QuerySet[StreamCount, StreamCount]", expected "QuerySet[CountT, CountT]") [return-value]- analytics/views/stats.py:583: error: Incompatible return value type (got "QuerySet[InstallationCount, InstallationCount]", expected "QuerySet[CountT, CountT]") [return-value]- analytics/views/stats.py:585: error: Incompatible return value type (got "QuerySet[RemoteInstallationCount, RemoteInstallationCount]", expected "QuerySet[CountT, CountT]") [return-value]- analytics/views/stats.py:587: error: Incompatible return value type (got "QuerySet[RemoteRealmCount, RemoteRealmCount]", expected "QuerySet[CountT, CountT]") [return-value]
artigraph (https://github.com/artigraph/artigraph)
+ src/arti/views/__init__.py:98: error: Incompatible types in assignment (expression has type "type[View] | None", variable has type "type[Self]") [assignment]+ src/arti/views/__init__.py:102: error: Incompatible types in assignment (expression has type "type[View] | None", variable has type "type[Self]") [assignment]
xarray (https://github.com/pydata/xarray)
+ xarray/indexes/nd_point_index.py: note: In member "from_variables" of class "NDPointIndex":+ xarray/indexes/nd_point_index.py:271: error: Incompatible types in assignment (expression has type "type[ScipyKDTreeAdapter]", variable has type "type[T_TreeAdapter]") [assignment] |
Uh oh!
There was an error while loading. Please reload this page.
Maybe a little ad hoc, but avoids some of the undesirable primer regression from #20492
Closes#20636