[ty] Gradual isinstance narrowing for generic classes - #27308
Conversation
isinstance narrowing using specialization filtering
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 96.96%. The percentage of expected errors that received a diagnostic held steady at 92.77%. The number of fully passing files held steady at 105/133. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
8 | 1,037 | 100 |
invalid-assignment |
1 | 222 | 37 |
unresolved-attribute |
7 | 109 | 36 |
invalid-return-type |
1 | 115 | 27 |
no-matching-overload |
1 | 87 | 0 |
invalid-key |
2 | 0 | 53 |
unsupported-operator |
0 | 46 | 2 |
not-subscriptable |
0 | 39 | 1 |
not-iterable |
0 | 15 | 3 |
call-non-callable |
2 | 10 | 1 |
invalid-yield |
0 | 10 | 2 |
redundant-cast |
4 | 7 | 0 |
unused-ignore-comment |
5 | 0 | 0 |
unused-type-ignore-comment |
3 | 2 | 0 |
invalid-type-form |
0 | 0 | 2 |
call-top-callable |
0 | 1 | 0 |
unknown-argument |
0 | 1 | 0 |
| Total | 34 | 1,701 | 264 |
Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.
Showing a random sample of 227 of 1999 changes. See the HTML report for the full diff.
Raw diff sample (227 of 1999 changes)
Expression (https://github.com/cognitedata/Expression)
- expression/collections/maptree.py:113:25 error[invalid-argument-type] Argument to function `mk` is incorrect: Expected `Option[MapTreeLeaf[Top[SupportsLessThan] | Unknown, object]]`, found `Option[MapTreeLeaf[Key@rebalance, Value@rebalance]]`
- expression/collections/maptree.py:121:27 error[invalid-argument-type] Argument to function `mk` is incorrect: Expected `Option[MapTreeLeaf[Top[SupportsLessThan] | Unknown, object]]`, found `Option[MapTreeLeaf[Key@rebalance, Value@rebalance]]`
- expression/collections/maptree.py:132:32 error[invalid-return-type] Return type does not match returned value: expected `Option[MapTreeLeaf[Key@rebalance, Value@rebalance]]`, found `Option[MapTreeLeaf[Unknown | Top[SupportsLessThan], object]]`
- expression/collections/maptree.py:141:61 error[invalid-argument-type] Argument to function `mk` is incorrect: Expected `Option[MapTreeLeaf[Unknown | Top[SupportsLessThan], object]]`, found `Option[MapTreeLeaf[Key@rebalance, Value@rebalance]]`
- expression/core/fn.py:58:23 warning[redundant-cast] Value is already of type `TailCall[_P@tailrec_async]`
PyGithub (https://github.com/PyGithub/PyGithub)
+ github/AdvisoryCredit.py:122:26 error[unresolved-attribute] Attribute `login` is not defined on `SimpleCredit & ~Top[dict[Unknown, Unknown]]` in union `(SimpleCredit & ~Top[dict[Unknown, Unknown]]) | (AdvisoryCredit & ~Top[dict[Unknown, Unknown]])`
+ github/AdvisoryCredit.py:123:25 error[unresolved-attribute] Attribute `type` is not defined on `SimpleCredit & ~Top[dict[Unknown, Unknown]]` in union `(SimpleCredit & ~Top[dict[Unknown, Unknown]]) | (AdvisoryCredit & ~Top[dict[Unknown, Unknown]])`
- github/AdvisoryVulnerability.py:129:59 error[invalid-assignment] Object of type `object` is not assignable to `SimpleAdvisoryVulnerabilityPackage`
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/commands/slash.py:1785:30 error[not-iterable] Object of type `Sequence[((int, /, *args: Any, **kwargs: Any) -> Coroutine[Any, Any, Any] | Any) | ((str, /, *args: Any, **kwargs: Any) -> Coroutine[Any, Any, Any] | Any)] | ((int, /, *args: Any, **kwargs: Any) -> Coroutine[Any, Any, Any] | Any) | ((str, /, *args: Any, **kwargs: Any) -> Coroutine[Any, Any, Any] | Any)` may not be iterable
- tanjun/commands/slash.py:1795:63 error[invalid-argument-type] Argument is incorrect: Expected `str | float`, found `object`
- tanjun/commands/slash.py:2078:97 error[invalid-assignment] Object of type `None | Mapping[str, str] | (Sequence[str] & Top[Mapping[Unknown, object]]) | (Sequence[tuple[str, str]] & Top[Mapping[Unknown, object]]) | (Sequence[CommandChoice] & Top[Mapping[Unknown, object]])` is not assignable to `Mapping[str, str] | list[CommandChoice] | None`
aiohttp (https://github.com/aio-libs/aiohttp)
- aiohttp/client.py:1225:37 error[invalid-argument-type] Argument to bound method `MultiDict.add` is incorrect: Expected `str`, found `object`
- aiohttp/cookiejar.py:345:27 error[invalid-argument-type] Method `__getitem__` of type `bound method Morsel[str].__getitem__(key: str, /) -> Any` cannot be called with key of type `Literal[-1]` on object of type `Morsel[str]`
- aiohttp/cookiejar.py:355:27 error[invalid-argument-type] Method `__getitem__` of type `bound method Morsel[str].__getitem__(key: str, /) -> Any` cannot be called with key of type `Literal[0]` on object of type `Morsel[str]`
- aiohttp/cookiejar.py:374:20 error[unresolved-attribute] Attribute `rstrip` is not defined on `Morsel[str] & ~AlwaysFalsy` in union `(Morsel[str] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | str`
altair (https://github.com/vega/altair)
+ altair/vegalite/v6/api.py:2506:34 warning[unused-ignore-comment] Unused blanket `ty: ignore` directive
+ altair/vegalite/v6/api.py:3102:70 warning[unused-ignore-comment] Unused blanket `ty: ignore` directive
+ altair/vegalite/v6/api.py:3790:56 warning[unused-ignore-comment] Unused blanket `ty: ignore` directive
anyio (https://github.com/agronholm/anyio)
- src/anyio/_backends/_trio.py:115:20 error[invalid-return-type] Return type does not match returned value: expected `Coroutine[Any, Any, T_Retval@ensure_returns_coro]`, found `Awaitable[T_Retval@ensure_returns_coro] & Coroutine[object, Never, object]`
- src/anyio/_core/_sockets.py:994:38 error[invalid-argument-type] Argument is incorrect: Expected `str | IPv4Address | IPv6Address`, found `object`
apprise (https://github.com/caronc/apprise)
- apprise/config/base.py:1255:29 error[no-matching-overload] No overload of bound method `MutableMapping.update` matches arguments
archinstall (https://github.com/archlinux/archinstall)
- archinstall/tui/components.py:1320:29 error[invalid-assignment] Object of type `object` is not assignable to `ValueT@_AppInstance | None`
artigraph (https://github.com/artigraph/artigraph)
- src/arti/storage/_internal.py:146:9 error[invalid-assignment] Invalid subscript assignment with key of type `str` and value of type `object` on object of type `dict[str, str]`
black (https://github.com/psf/black)
- src/black/ranges.py:508:26 error[invalid-argument-type] Argument to function `last_leaf` is incorrect: Expected `Leaf | Node`, found `object`
bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/util/datatypes.py:89:13 warning[redundant-cast] Value is already of type `set[V@MultiValuedDict]`
- src/bokeh/util/datatypes.py:111:24 warning[redundant-cast] Value is already of type `set[V@MultiValuedDict]`
- src/bokeh/core/property/bases.py:264:41 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `object` on object of type `Top[dict[Unknown, Unknown]]`
- src/bokeh/embed/standalone.py:260:18 error[invalid-assignment] Object of type `list[object]` is not assignable to `Model | Sequence[Model] | dict[str, Model]`
- src/bokeh/plotting/contour.py:305:41 error[invalid-argument-type] Argument to function `_palette_from_collection` is incorrect: Expected `PaletteCollection`, found `(Sequence[ColorLike] & Top[dict[Unknown, Unknown]]) | (Color & Top[dict[Unknown, Unknown]]) | dict[int, Palette]`
cloud-init (https://github.com/canonical/cloud-init)
- cloudinit/distros/gentoo.py:141:19 error[invalid-argument-type] Argument to function `subp` is incorrect: Expected `str | bytes | list[str] | list[bytes]`, found `list[object]`
core (https://github.com/home-assistant/core)
- homeassistant/helpers/integration_platform.py:366:30 error[invalid-assignment] Object of type `object` is not assignable to `_R@LazyIntegrationPlatforms | None`
- homeassistant/components/rest/data.py:51:44 error[invalid-argument-type] Argument to constructor `BasicAuth.__new__` is incorrect: Expected `str`, found `object`
cwltool (https://github.com/common-workflow-language/cwltool)
- cwltool/builder.py:240:58 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["name"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/builder.py:273:21 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/builder.py:276:17 error[invalid-assignment] Cannot assign to a subscript on an object of type `int`
- cwltool/builder.py:279:21 error[invalid-assignment] Cannot assign to a subscript on an object of type `str`
- cwltool/builder.py:670:24 error[invalid-return-type] Return type does not match returned value: expected `float | str | CWLFileType | ... omitted 4 union elements`, found `dict[object, float | str | CWLFileType | ... omitted 4 union elements]`
- cwltool/checker.py:115:12 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/checker.py:123:12 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/checker.py:133:43 error[invalid-key] Unknown key "type" for TypedDict `CWLDirectoryType` (subscripted object has type `(int & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]]) | (float* & Top[MutableMapping[Unknown, Unknown]]) | ... omitted 5 union elements`)
+ cwltool/checker.py:133:43 error[invalid-key] Unknown key "type" for TypedDict `CWLDirectoryType` (subscripted object has type `(int & MutableMapping[Unknown, Unknown]) | (str & MutableMapping[Unknown, Unknown]) | (float* & MutableMapping[Unknown, Unknown]) | ... omitted 5 union elements`)
- cwltool/checker.py:133:57 error[invalid-key] Unknown key "type" for TypedDict `CWLDirectoryType` (subscripted object has type `(int & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]]) | (float* & Top[MutableMapping[Unknown, Unknown]]) | ... omitted 5 union elements`)
+ cwltool/checker.py:133:57 error[invalid-key] Unknown key "type" for TypedDict `CWLDirectoryType` (subscripted object has type `(int & MutableMapping[Unknown, Unknown]) | (str & MutableMapping[Unknown, Unknown]) | (float* & MutableMapping[Unknown, Unknown]) | ... omitted 5 union elements`)
- cwltool/checker.py:133:39 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/checker.py:133:39 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/checker.py:133:39 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/checker.py:133:52 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/command_line_tool.py:645:33 error[invalid-assignment] Invalid subscript assignment with key of type `Literal["writable"]` and value of type `object` on object of type `MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]`
- cwltool/command_line_tool.py:1571:17 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Divergent, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[Divergent]]` cannot be called with key of type `Literal["type"]` on object of type `MutableSequence[Divergent]`
- cwltool/command_line_tool.py:1571:17 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/command_line_tool.py:1574:52 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["fields"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/load_tool.py:178:33 error[invalid-assignment] Invalid subscript assignment with key of type `Literal["stdout", "stderr"]` and value of type `str` on object of type `MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements] | str | int]`
- cwltool/load_tool.py:337:27 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/load_tool.py:233:13 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements] | str, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements] | str]]` cannot be called with key of type `Literal["run"]` on object of type `MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements] | str]`
- cwltool/main.py:199:32 error[invalid-argument-type] Argument to bound method `MutableSequence.remove` is incorrect: Expected `Never`, found `Literal["null"]`
- cwltool/main.py:212:63 error[invalid-argument-type] Argument to function `generate_example_input` is incorrect: Expected `float | str | CWLFileType | ... omitted 4 union elements`, found `object`
- cwltool/main.py:296:27 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/main.py:300:74 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/main.py:304:27 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["type"]` on object of type `str`
- cwltool/main.py:305:17 error[invalid-assignment] Cannot assign to a subscript on an object of type `str`
- cwltool/main.py:307:63 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/main.py:310:25 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["items"]` on object of type `str`
- cwltool/main.py:310:85 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["items"]` on object of type `str`
- cwltool/main.py:319:17 error[invalid-assignment] Cannot assign to a subscript on an object of type `str`
- cwltool/main.py:405:12 error[invalid-return-type] Return type does not match returned value: expected `tuple[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements] | None, str, Loader]`, found `tuple[None | (int & Top[MutableMapping[Unknown, Unknown]]) | (float* & Top[MutableMapping[Unknown, Unknown]]) | ... omitted 3 union elements, Unknown | str, Loader]`
- cwltool/pack.py:30:38 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["run"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/pack.py:30:38 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["run"]` on object of type `str`
+ cwltool/pack.py:106:88 error[invalid-key] TypedDict `CWLDirectoryType` can only be subscripted with a string literal key, got key of type `str`
- cwltool/pack.py:47:38 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["id"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/pack.py:47:38 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["id"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/pack.py:48:35 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["name"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/pack.py:48:35 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["name"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/pack.py:93:31 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["name"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/pack.py:94:39 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["id"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/process.py:448:17 error[invalid-assignment] Invalid subscript assignment with key of type `int` and value of type `MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements] | MutableSequence[Any] | float | ... omitted 6 union elements` on object of type `MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]`
- cwltool/process.py:1095:58 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Divergent, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[Divergent]]` cannot be called with key of type `Literal["requirements"]` on object of type `MutableSequence[Divergent]`
- cwltool/process.py:1095:58 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements], (index: slice[int | None, int | None, int | None], /) -> MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]]]` cannot be called with key of type `Literal["requirements"]` on object of type `MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]]`
- cwltool/process.py:1095:58 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["requirements"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- cwltool/process.py:1097:37 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements], (index: slice[int | None, int | None, int | None], /) -> MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]]]` cannot be called with key of type `Literal["requirements"]` on object of type `MutableSequence[MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]]`
- cwltool/secrets.py:64:39 error[invalid-argument-type] Argument to bound method `SecretStore.retrieve` is incorrect: Expected `float | str | CWLFileType | ... omitted 3 union elements`, found `object`
- cwltool/utils.py:195:13 error[invalid-assignment] Invalid subscript assignment with key of type `str | Any` and value of type `str | MutableSequence[Any] | MutableMapping[str, Any]` on object of type `MutableSequence[Any]`
- cwltool/workflow_job.py:335:28 error[invalid-argument-type] Argument to function `match_types` is incorrect: Expected `float | str | CWLFileType | ... omitted 5 union elements`, found `object`
- cwltool/workflow_job.py:342:13 error[invalid-assignment] Invalid subscript assignment with key of type `Literal["type"]` and value of type `object` on object of type `MutableMapping[str, float | str | CWLFileType | ... omitted 4 union elements]`
dd-trace-py (https://github.com/DataDog/dd-trace-py)
- scripts/view_trace_snapshot.py:24:16 error[invalid-return-type] Return type does not match returned value: expected `list[list[dict[str, object]]]`, found `Top[list[Unknown]] & ~AlwaysFalsy`
- ddtrace/appsec/_api_security/_normalized_route.py:1083:61 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Any, (index: slice[int | None, int | None, int | None], /) -> Sequence[Any]]` cannot be called with key of type `object` on object of type `Sequence[Any]`
- ddtrace/appsec/_api_security/_normalized_route.py:1083:61 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[Mapping[Unknown, object]].__getitem__(key: Never, /) -> object` cannot be called with key of type `object` on object of type `Top[Mapping[Unknown, object]]`
discord.py (https://github.com/Rapptz/discord.py)
- discord/channel.py:1275:31 error[unresolved-attribute] Object of type `object` has no attribute `id`
- discord/ext/commands/cog.py:527:13 error[unresolved-attribute] Unresolved attribute `__cog_listener__` on type `(...) -> Coroutine[Any, Any, Any]`
+ discord/ext/commands/cog.py:527:13 error[unresolved-attribute] Unresolved attribute `__cog_listener__` on type `(...) -> Unknown`
- discord/utils.py:1047:19 error[invalid-yield] Yield type `list[object]` does not match annotated yield type `list[T@_chunk]`
ibis (https://github.com/ibis-project/ibis)
- ibis/expr/types/relations.py:3222:28 error[invalid-argument-type] Method `__getitem__` of type `bound method Schema.__getitem__(name: str) -> DataType` cannot be called with key of type `object` on object of type `Schema`
jax (https://github.com/google/jax)
- jax/_src/numpy/lax_numpy.py:4983:37 error[invalid-argument-type] Argument to function `_block` is incorrect: Expected `Array | ndarray[tuple[Any, ...], dtype[Any]] | numpy.bool[builtins.bool] | ... omitted 3 union elements`, found `object`
jinja (https://github.com/pallets/jinja)
- src/jinja2/filters.py:169:48 error[invalid-assignment] Object of type `dict_items[object, object]` is not assignable to `Iterable[tuple[str, Any]]`
+ src/jinja2/filters.py:169:48 error[invalid-assignment] Object of type `dict_items[str, Any] | dict_items[tuple[str, Any], Unknown]` is not assignable to `Iterable[tuple[str, Any]]`
- src/jinja2/parser.py:1024:37 error[invalid-argument-type] Argument to bound method `list.extend` is incorrect: Expected `Iterable[Node]`, found `(Node & Top[list[Unknown]]) | list[Node]`
koda-validate (https://github.com/keithasaurus/koda-validate)
- koda_validate/_internal.py:214:24 error[invalid-return-type] Return type does not match returned value: expected `tuple[Literal[True], A@_union_validator] | tuple[Literal[False], Invalid]`, found `tuple[Literal[True], object]`
+ koda_validate/_internal.py:214:24 error[invalid-return-type] Return type does not match returned value: expected `tuple[Literal[True], A@_union_validator] | tuple[Literal[False], Invalid]`, found `tuple[Literal[True], Any | Invalid]`
- koda_validate/serialization/json_schema.py:334:17 error[invalid-return-type] Return type does not match returned value: expected `dict[str, None | float | str | ... omitted 3 union elements]`, found `dict[str, None | float | str | ... omitted 5 union elements]`
- koda_validate/serialization/json_schema.py:362:17 error[invalid-return-type] Return type does not match returned value: expected `dict[str, None | float | str | ... omitted 3 union elements]`, found `dict[str, None | float | str | ... omitted 5 union elements]`
kopf (https://github.com/nolar/kopf)
- kopf/_cogs/structs/patches.py:159:45 error[invalid-argument-type] Argument to bound method `Patch._apply_patch` is incorrect: Expected `tuple[str, ...]`, found `tuple[object, ...]`
- kopf/_kits/hierarchies.py:44:24 error[no-matching-overload] No overload of bound method `MutableMapping.setdefault` matches arguments
- kopf/_kits/hierarchies.py:215:38 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["metadata"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/feature_benchmark/benchmark.py:157:17 error[unresolved-attribute] Attribute `run` is not defined on `None` in union `None | Action`
meson (https://github.com/mesonbuild/meson)
- mesonbuild/cargo/manifest.py:766:40 error[no-matching-overload] No overload of function `normpath` matches arguments
- mesonbuild/cmake/interpreter.py:1048:40 error[invalid-argument-type] Argument to function `nodeify` is incorrect: Expected `Sequence[str | int | Path | BaseNode] | int | Path | BaseNode`, found `~None`
- mesonbuild/interpreterbase/decorators.py:780:64 error[invalid-argument-type] Argument to function `version_compare_condition_with_min` is incorrect: Expected `str | Range[Version]`, found `Range[Version] | (NoProjectVersion & Top[Range[Unknown]])`
- mesonbuild/options.py:343:16 error[invalid-return-type] Return type does not match returned value: expected `str | int | list[str]`, found `(_T@UserOption & str) | (_T@UserOption & int) | (_T@UserOption & Top[list[Unknown]])`
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- pymongo/helpers_shared.py:189:21 error[invalid-argument-type] Method `__getitem__` of type `bound method Mapping[str, Any].__getitem__(key: str, /) -> Any` cannot be called with key of type `tuple[str, int | str | Mapping[str, Any]]` on object of type `Mapping[str, Any]`
- pymongo/helpers_shared.py:189:21 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[Mapping[Unknown, object]].__getitem__(key: Never, /) -> object` cannot be called with key of type `tuple[str, int | str | Mapping[str, Any]]` on object of type `Top[Mapping[Unknown, object]]`
mypy (https://github.com/python/mypy)
- mypy/test/test_diff_cache.py:127:42 error[unsupported-operator] Operator `in` is not supported between objects of type `Literal["/c."]` and `object`
- mypy/test/test_diff_cache.py:128:42 error[unsupported-operator] Operator `in` is not supported between objects of type `Literal["/a."]` and `object`
- mypy/test/test_diff_cache.py:128:56 error[unresolved-attribute] Object of type `object` has no attribute `startswith`
optuna (https://github.com/optuna/optuna)
- optuna/study/study.py:520:13 error[invalid-argument-type] Argument to function `_optimize` is incorrect: Expected `tuple[type[Exception], ...]`, found `tuple[object, ...]`
packaging (https://github.com/pypa/packaging)
- src/packaging/specifiers.py:925:17 error[invalid-assignment] Object of type `tuple[object, ...]` is not assignable to attribute `_specs` of type `tuple[Specifier, ...]`
- src/packaging/tags.py:164:16 error[invalid-return-type] Return type does not match returned value: expected `str`, found `object`
- src/packaging/tags.py:171:16 error[invalid-return-type] Return type does not match returned value: expected `str`, found `object`
- src/packaging/tags.py:203:16 error[invalid-return-type] Return type does not match returned value: expected `tuple[str, str, str]`, found `tuple[object, object, object]`
- src/packaging/version.py:827:29 error[unresolved-attribute] Object of type `~None` has no attribute `pre`
pandas (https://github.com/pandas-dev/pandas)
- pandas/core/arrays/_mixins.py:213:16 error[no-matching-overload] No overload of function `maybe_convert_objects` matches arguments
- pandas/core/arrays/datetimelike.py:665:21 error[no-matching-overload] No overload of function `maybe_convert_objects` matches arguments
- pandas/core/indexes/multi.py:4838:59 error[invalid-argument-type] Argument to function `len` is incorrect: Expected `Sized`, found `object`
- pandas/core/reshape/concat.py:832:17 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[Mapping[Unknown, object]].__getitem__(key: Never, /) -> object` cannot be called with key of type `object` on object of type `Top[Mapping[Unknown, object]]`
+ pandas/core/reshape/concat.py:832:17 error[invalid-argument-type] Method `__getitem__` of type `bound method Mapping[Series | DataFrame, Unknown].__getitem__(key: Series | DataFrame, /) -> Unknown` cannot be called with key of type `HashableT@_clean_keys_and_objs` on object of type `Mapping[Series | DataFrame, Unknown]`
- pandas/io/excel/_base.py:868:21 error[unsupported-operator] Operator `+=` is not supported between objects of type `object` and `int`
- pandas/io/formats/printing.py:282:13 error[no-matching-overload] No overload of bound method `MutableMapping.update` matches arguments
- pandas/io/parsers/python_parser.py:138:13 error[invalid-assignment] Object of type `(ReadCsvBuffer[str] & Top[list[Unknown]]) | list[Unknown]` is not assignable to attribute `data` of type `Iterator[list[str]] | list[list[str | bytes | date | ... omitted 8 union elements]]`
- pandas/io/parsers/python_parser.py:879:45 error[invalid-argument-type] Argument to bound method `PythonParser._is_line_empty` is incorrect: Expected `Sequence[str | bytes | date | ... omitted 8 union elements]`, found `object`
- pandas/io/stata.py:2933:21 error[invalid-argument-type] Argument to function `isfile` is incorrect: Expected `int | str | bytes | PathLike[str] | PathLike[bytes]`, found `str | PathLike[str] | (WriteBuffer[bytes] & Top[PathLike[Unknown]])`
pip (https://github.com/pypa/pip)
- src/pip/_internal/network/utils.py:120:41 error[invalid-assignment] Object of type `object` is not assignable to `float | None`
- src/pip/_vendor/packaging/specifiers.py:925:17 error[invalid-assignment] Object of type `tuple[object, ...]` is not assignable to attribute `_specs` of type `tuple[Specifier, ...]`
- src/pip/_vendor/cachecontrol/controller.py:443:21 error[invalid-argument-type] Argument to bound method `CacheController._cache_set` is incorrect: Expected `HTTPResponse`, found `~None`
- src/pip/_vendor/packaging/version.py:804:21 error[invalid-assignment] Object of type `object` is not assignable to attribute `_post` of type `tuple[Literal["post"], int] | None`
- src/pip/_vendor/packaging/version.py:817:21 error[invalid-assignment] Object of type `object` is not assignable to attribute `_dev` of type `tuple[Literal["dev"], int] | None`
- src/pip/_vendor/packaging/version.py:828:30 error[unresolved-attribute] Object of type `~None` has no attribute `post`
- src/pip/_vendor/pkg_resources/__init__.py:2840:21 error[invalid-assignment] Object of type `dict_items[object, object]` is not assignable to `Iterable[tuple[str | None, Iterable[str]]]`
ppb-vector (https://github.com/ppb/ppb-vector)
- ppb_vector/__init__.py:189:26 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[Mapping[Unknown, object]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["x"]` on object of type `Top[Mapping[Unknown, object]]`
psycopg (https://github.com/psycopg/psycopg)
- psycopg/psycopg/types/enum.py:231:30 error[not-iterable] Object of type `E@_make_load_map` is not iterable
- psycopg/psycopg/types/enum.py:249:30 error[not-iterable] Object of type `E@_make_dump_map` is not iterable
pwndbg (https://github.com/pwndbg/pwndbg)
- pwndbg/aglib/heap/ptmalloc.py:271:28 error[invalid-argument-type] Argument to constructor `int.__new__` is incorrect: Expected `str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc`, found `Value | None | int`
+ pwndbg/aglib/heap/ptmalloc.py:271:28 error[invalid-argument-type] Argument to constructor `int.__new__` is incorrect: Expected `str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc`, found `Value | None | Unknown`
- pwndbg/aglib/heap/ptmalloc.py:452:17 error[invalid-argument-type] Argument to constructor `int.__new__` is incorrect: Expected `str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc`, found `Value | None`
+ pwndbg/aglib/heap/ptmalloc.py:452:17 error[invalid-argument-type] Argument to constructor `int.__new__` is incorrect: Expected `str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc`, found `Value | None | Unknown`
- pwndbg/commands/__init__.py:420:33 error[unresolved-attribute] Object of type `object` has no attribute `prog`
- pwndbg/commands/ptmalloc2.py:54:15 error[call-non-callable] Object of type `Type` is not callable
- pwndbg/commands/ptmalloc2.py:466:11 error[unresolved-attribute] Attribute `value_to_human_readable` is not defined on `None` in union `Value | CStruct2GDB | None`
+ pwndbg/commands/ptmalloc2.py:466:11 error[unresolved-attribute] Attribute `value_to_human_readable` is not defined on `None` in union `Unknown | None`
- pwndbg/commands/ptmalloc2.py:1391:31 error[unresolved-attribute] Attribute `address` is not defined on `None` in union `Value | CStruct2GDB | None`
+ pwndbg/commands/ptmalloc2.py:1391:31 error[unresolved-attribute] Attribute `address` is not defined on `None` in union `Unknown | None`
pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/mark/structures.py:464:37 error[invalid-argument-type] Argument to function `normalize_mark_list` is incorrect: Expected `Iterable[Mark | MarkDecorator]`, found `list[object] | list[Unknown] | (Any & Top[list[Unknown]])`
schema_salad (https://github.com/common-workflow-language/schema_salad)
- src/schema_salad/avro/schema.py:804:44 error[invalid-argument-type] Argument to function `is_subtype` is incorrect: Expected `None | str | float | ... omitted 5 union elements`, found `object`
- src/schema_salad/avro/schema.py:809:38 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["items"]` on object of type `Top[dict[Unknown, Unknown]]`
- src/schema_salad/avro/schema.py:809:57 error[invalid-argument-type] Argument to function `is_subtype` is incorrect: Expected `None | str | float | ... omitted 5 union elements`, found `object`
- src/schema_salad/makedoc.py:788:26 error[invalid-argument-type] Argument to bound method `list.extend` is incorrect: Expected `Iterable[dict[str, Any]]`, found `(int & Top[MutableSequence[Unknown]]) | (float* & Top[MutableSequence[Unknown]]) | (str & Top[MutableSequence[Unknown]]) | (CommentedMap & Top[MutableSequence[Unknown]]) | CommentedSeq`
- src/schema_salad/metaschema.py:672:41 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/metaschema.py:697:29 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Any, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[Any]]` cannot be called with key of type `Literal["$graph"]` on object of type `MutableSequence[Any]`
- src/schema_salad/ref_resolver.py:1135:25 error[invalid-assignment] Cannot assign to a subscript on an object of type `str`
- src/schema_salad/ref_resolver.py:1135:61 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/ref_resolver.py:1154:29 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/ref_resolver.py:1155:62 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `str` on object of type `str`
- src/schema_salad/ref_resolver.py:1161:41 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/ref_resolver.py:1161:41 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/ref_resolver.py:1164:41 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/ref_resolver.py:1164:41 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `str` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/schema.py:434:30 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[Mapping[Unknown, object]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["name"]` on object of type `Top[Mapping[Unknown, object]]`
- src/schema_salad/schema.py:545:48 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Any, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[Any]]` cannot be called with key of type `Literal["name"]` on object of type `MutableSequence[Any]`
- src/schema_salad/schema.py:549:31 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["type"]` on object of type `str`
- src/schema_salad/schema.py:562:20 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Any, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[Any]]` cannot be called with key of type `Literal["name"]` on object of type `MutableSequence[Any]`
- src/schema_salad/schema.py:563:38 error[invalid-argument-type] Method `__getitem__` of type `Overload[(index: int, /) -> Any, (index: slice[int | None, int | None, int | None], /) -> MutableSequence[Any]]` cannot be called with key of type `Literal["name"]` on object of type `MutableSequence[Any]`
- src/schema_salad/schema.py:564:27 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["name"]` on object of type `str`
- src/schema_salad/schema.py:568:21 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["names"]` on object of type `Top[MutableMapping[Unknown, Unknown]]`
- src/schema_salad/schema.py:568:21 error[invalid-argument-type] Method `__getitem__` of type `bound method str.__getitem__(key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None], /) -> str` cannot be called with key of type `Literal["type"]` on object of type `str`
schemathesis (https://github.com/schemathesis/schemathesis)
- src/schemathesis/core/error_feedback/parsers/ajv.py:359:48 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["message"]` on object of type `Top[dict[Unknown, Unknown]]`
- src/schemathesis/core/error_feedback/parsers/marshmallow.py:159:36 error[invalid-assignment] Object of type `object` is not assignable to `str | int`
- src/schemathesis/core/error_feedback/parsers/marshmallow.py:164:23 error[invalid-yield] Yield type `tuple[tuple[str | int, ...], ParameterLocation, object]` does not match annotated yield type `tuple[tuple[str | int, ...], ParameterLocation, str]`
- src/schemathesis/core/error_feedback/parsers/rails.py:218:16 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["errors"]` on object of type `Top[dict[Unknown, Unknown]]`
- src/schemathesis/specs/openapi/_auth_retry.py:82:9 error[invalid-argument-type] Argument to `Case.__init__` is incorrect: Expected `dict[str, Divergent] | list[Divergent] | str | ... omitted 4 union elements`, found `Top[list[Unknown]] | Top[dict[Unknown, Unknown]] | str | ... omitted 4 union elements`
- src/schemathesis/openapi/checks.py:176:13 error[invalid-argument-type] Argument to `JsonSchemaError.__init__` is incorrect: Expected `dict[str, Any] | bool`, found `Top[dict[Unknown, Unknown]]`
- src/schemathesis/specs/openapi/_hypothesis.py:1095:24 error[invalid-argument-type] Argument to function `_snap_float32_node` is incorrect: Expected `dict[str, Any]`, found `Top[dict[Unknown, Unknown]]`
- src/schemathesis/specs/openapi/adapter/responses.py:402:16 error[invalid-return-type] Return type does not match returned value: expected `str | None`, found `object`
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/_vendor/pyproject_metadata/project_table.py:226:62 error[invalid-argument-type] Argument to function `sorted` is incorrect: Argument type `object` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
- src/scikit_build_core/_vendor/pyproject_metadata/project_table.py:277:16 error[no-matching-overload] No overload of bound method `Pattern.fullmatch` matches arguments
scikit-learn (https://github.com/scikit-learn/scikit-learn)
+ sklearn/externals/array_api_compat/common/_aliases.py:594:22 warning[redundant-cast] Value is already of type `tuple[Any | str, ...]`
- sklearn/manifold/_spectral_embedding.py:421:9 error[unsupported-operator] Operator `-=` is not supported between objects of type `csr_array[Top[number[Any, complex]] | numpy.bool[builtins.bool], tuple[int] | tuple[int, int]]` and `dia_array[float64] | Unknown`
+ sklearn/manifold/_spectral_embedding.py:421:9 error[unsupported-operator] Operator `-=` is not supported between objects of type `csr_array[Unknown, Unknown]` and `dia_array[float64] | Unknown`
- sklearn/utils/tests/test_plotting.py:351:16 error[not-subscriptable] Cannot subscript object of type `object` with no `__getitem__` method
scipy (https://github.com/scipy/scipy)
- scipy/special/tests/test_cdflib.py:114:54 error[invalid-argument-type] Argument to constructor `zip.__new__` is incorrect: Expected `Iterable[Unknown | None]`, found `None | (Unknown & Top[list[Unknown]]) | list[Unknown | None]`
+ scipy/special/tests/test_cdflib.py:114:54 error[invalid-argument-type] Argument to constructor `zip.__new__` is incorrect: Expected `Iterable[Unknown | None]`, found `None | (Unknown & list[Unknown]) | list[Unknown | None]`
- subprojects/array_api_extra/src/array_api_extra/testing.py:276:26 error[invalid-argument-type] Argument to function `getattr` is incorrect: Expected `str`, found `object`
- subprojects/array_api_extra/src/array_api_extra/testing.py:285:9 error[invalid-assignment] Object of type `dict[str, int | type]` is not assignable to attribute `_lazy_xp_function` on type `Unknown | (((...) -> Any) & ~tuple[object, ...])`
+ subprojects/array_api_extra/src/array_api_extra/testing.py:285:9 error[invalid-assignment] Object of type `dict[str, int | type]` is not assignable to attribute `_lazy_xp_function` on type `Any | (((...) -> Any) & ~tuple[object, ...])`
- subprojects/highs/highs/highspy/highs.py:383:65 error[invalid-assignment] Object of type `Iterable[highs_var | Integral] & Top[Mapping[Unknown, object]]` is not assignable to `Mapping[Any, highs_var | Integral]`
scrapy (https://github.com/scrapy/scrapy)
- scrapy/exporters.py:124:58 error[invalid-argument-type] Argument to bound method `BaseItemExporter.serialize_field` is incorrect: Expected `str`, found `object`
- scrapy/exporters.py:335:26 error[invalid-assignment] Object of type `ValuesView[object]` is not assignable to `Iterable[str]`
setuptools (https://github.com/pypa/setuptools)
- setuptools/_distutils/command/build_ext.py:445:30 error[not-iterable] Object of type `~AlwaysFalsy` is not iterable
spack (https://github.com/spack/spack)
- lib/spack/spack/audit.py:1463:82 error[invalid-argument-type] Argument to function `sorted` is incorrect: Argument type `object` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
- lib/spack/spack/cmd/commands.py:567:34 error[invalid-argument-type] Argument to function `sorted` is incorrect: Argument type `object` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
spark (https://github.com/apache/spark)
- python/pyspark/ml/functions.py:794:17 error[invalid-assignment] Invalid subscript assignment with key of type `object` and value of type `object` on object of type `list[list[int] | None]`
- python/pyspark/pandas/data_type_ops/boolean_ops.py:326:52 error[invalid-argument-type] Argument to function `_as_categorical_type` is incorrect: Expected `CategoricalDtype[object]`, found `Top[CategoricalDtype[Unknown]]`
- python/pyspark/pandas/data_type_ops/datetime_ops.py:145:52 error[invalid-argument-type] Argument to function `_as_categorical_type` is incorrect: Expected `CategoricalDtype[object]`, found `Top[CategoricalDtype[Unknown]]`
- python/pyspark/sql/classic/table_arg.py:44:20 error[invalid-assignment] Object of type `Column & Top[list[Unknown]]` is not assignable to `tuple[Column | str, ...]`
+ python/pyspark/sql/classic/table_arg.py:44:20 error[invalid-assignment] Object of type `Column & list[Unknown]` is not assignable to `tuple[Column | str, ...]`
- python/pyspark/sql/connect/functions/builtin.py:1717:16 error[invalid-assignment] Object of type `(Column & Top[list[Unknown]]) | (Sequence[Column | str] & Top[list[Unknown]]) | (Column & Top[set[Unknown]]) | ... omitted 3 union elements` is not assignable to `tuple[Column | Sequence[Column | str], ...]`
+ python/pyspark/sql/connect/functions/builtin.py:1717:16 error[invalid-assignment] Object of type `(Column & list[Unknown]) | (Column & set[Unknown]) | (Column & tuple[Unknown, ...]) | ... omitted 3 union elements` is not assignable to `tuple[Column | Sequence[Column | str], ...]`
- python/pyspark/sql/connect/window.py:35:16 error[invalid-assignment] Object of type `(Column & Top[list[Unknown]]) | (Sequence[Column | str] & Top[list[Unknown]])` is not assignable to `tuple[Column | Sequence[Column | str], ...]`
+ python/pyspark/sql/connect/window.py:35:16 error[invalid-assignment] Object of type `(Column & list[Unknown]) | list[Column | str]` is not assignable to `tuple[Column | Sequence[Column | str], ...]`
- python/pyspark/sql/session.py:1234:60 error[invalid-argument-type] Argument to bound method `SparkSession._inferSchema` is incorrect: Expected `list[str] | None`, found `None | (DataType & Top[list[Unknown]]) | list[str] | (DataType & tuple[object, ...])`
+ python/pyspark/sql/session.py:1234:60 error[invalid-argument-type] Argument to bound method `SparkSession._inferSchema` is incorrect: Expected `list[str] | None`, found `None | (DataType & list[Unknown]) | (DataType & tuple[Unknown, ...]) | list[str]`
- python/pyspark/sql/types.py:2809:17 error[invalid-assignment] Object of type `list[tuple[object, object]]` is not assignable to `Iterable[tuple[str, Any]]`
- python/pyspark/testing/sqlutils.py:310:21 error[invalid-assignment] Invalid subscript assignment with key of type `object` and value of type `str` on object of type `_Environ[str]`
- python/pyspark/testing/utils.py:1026:18 error[unresolved-attribute] Attribute `select` is not defined on `list[Row]` in union `pyspark.sql.dataframe.DataFrame | (pandas.core.frame.DataFrame & Top[list[Unknown]]) | (pyspark.pandas.frame.DataFrame[Unknown] & Top[list[Unknown]]) | list[Row]`
+ python/pyspark/testing/utils.py:1026:18 error[unresolved-attribute] Attribute `select` is not defined on `list[Row]` in union `pyspark.sql.dataframe.DataFrame | (pandas.core.frame.DataFrame & list[Unknown]) | (pyspark.pandas.frame.DataFrame[Unknown] & list[Unknown]) | list[Row]`
- python/pyspark/testing/utils.py:1035:43 error[invalid-argument-type] Argument to function `rename_dataframe_columns` is incorrect: Expected `pyspark.sql.dataframe.DataFrame`, found `pyspark.sql.dataframe.DataFrame | (pandas.core.frame.DataFrame & Top[list[Unknown]]) | (pyspark.pandas.frame.DataFrame[Unknown] & Top[list[Unknown]]) | list[Row] | Unknown`
+ python/pyspark/testing/utils.py:1035:43 error[invalid-argument-type] Argument to function `rename_dataframe_columns` is incorrect: Expected `pyspark.sql.dataframe.DataFrame`, found `pyspark.sql.dataframe.DataFrame | (pandas.core.frame.DataFrame & list[Unknown]) | (pyspark.pandas.frame.DataFrame[Unknown] & list[Unknown]) | list[Row] | Unknown`
static-frame (https://github.com/static-frame/static-frame)
- static_frame/core/frame.py:5483:20 error[no-matching-overload] No overload of bound method `Frame._extract` matches arguments
- static_frame/core/index_hierarchy.py:1754:19 error[invalid-assignment] Object of type `int | (list[int] & Top[integer[Unknown]])` is not assignable to `int | None`
+ static_frame/core/index_hierarchy.py:1754:19 error[invalid-assignment] Object of type `int | (list[int] & integer[Unknown])` is not assignable to `int | None`
+ static_frame/core/store.py:394:24 error[invalid-argument-type] Argument to function `insert` is incorrect: Expected `Hashable | complex | integer[Any] | ... omitted 8 union elements`, found `Hashable | complex | integer[Any] | ... omitted 9 union elements`
- static_frame/core/type_blocks.py:3777:35 error[invalid-argument-type] Argument to bound method `list.append` is incorrect: Expected `Never`, found `ndarray[tuple[Any, ...], dtype[Any]]`
steam.py (https://github.com/Gobot1234/steam.py)
- steam/trade.py:401:13 error[invalid-assignment] Object of type `Sequence[ReceivingAssetT@TradeOffer] | (ReceivingAssetT@TradeOffer & Sequence[object]) | list[Unknown]` is not assignable to `Sequence[ReceivingAssetT@TradeOffer]`: Incompatible value of type `Sequence[ReceivingAssetT@TradeOffer] | (ReceivingAssetT@TradeOffer & Sequence[object]) | list[Unknown]`
strawberry (https://github.com/strawberry-graphql/strawberry)
- strawberry/codegen/plugins/python.py:135:62 error[invalid-argument-type] Argument to bound method `PythonPlugin._print_argument_value` is incorrect: Expected `GraphQLStringValue | GraphQLNullValue | GraphQLIntValue | ... omitted 6 union elements`, found `object`
- strawberry/http/sync_base_view.py:96:21 error[invalid-argument-type] Argument to bound method `SyncBaseHTTPView.execute_single` is incorrect: Expected `GraphQLRequestData`, found `object`
- strawberry/http/sync_base_view.py:270:41 error[unresolved-attribute] Object of type `object` has no attribute `errors`
sympy (https://github.com/sympy/sympy)
- sympy/physics/quantum/operatorset.py:128:34 error[invalid-argument-type] Method `__getitem__` of type `bound method dict[frozenset[<class 'J2Op'> | <class 'JxOp'>] | frozenset[<class 'J2Op'> | <class 'JyOp'>] | frozenset[<class 'J2Op'> | <class 'JzOp'>] | ... omitted 4 union elements, <class 'JxKet'> | <class 'JyKet'> | <class 'JzKet'> | ... omitted 4 union elements].__getitem__(key: frozenset[<class 'J2Op'> | <class 'JxOp'>] | frozenset[<class 'J2Op'> | <class 'JyOp'>] | frozenset[<class 'J2Op'> | <class 'JzOp'>] | ... omitted 4 union elements, /) -> <class 'JxKet'> | <class 'JyKet'> | <class 'JzKet'> | ... omitted 4 union elements` cannot be called with key of type `frozenset[type]` on object of type `dict[frozenset[<class 'J2Op'> | <class 'JxOp'>] | frozenset[<class 'J2Op'> | <class 'JyOp'>] | frozenset[<class 'J2Op'> | <class 'JzOp'>] | ... omitted 4 union elements, <class 'JxKet'> | <class 'JyKet'> | <class 'JzKet'> | ... omitted 4 union elements]`
- sympy/ntheory/tests/test_factor_.py:64:16 error[unsupported-operator] Operator `%` is not supported between objects of type `~AlwaysFalsy & ~Literal[1] & ~Literal[True]` and `Literal[2]`
- sympy/polys/domains/polynomialring.py:51:35 error[invalid-assignment] Object of type `Domain[Er@PolynomialRing] | Domain[Er@PolyRing]` is not assignable to `Domain[Er@PolynomialRing]`: Incompatible value of type `Domain[Er@PolynomialRing] | Domain[Er@PolyRing]`
+ sympy/polys/domains/polynomialring.py:51:35 error[invalid-assignment] Object of type `Domain[Unknown] | Domain[Er@PolynomialRing] | Domain[Er@PolyRing]` is not assignable to `Domain[Er@PolynomialRing]`: Incompatible value of type `Domain[Unknown] | Domain[Er@PolynomialRing] | Domain[Er@PolyRing]`
+ sympy/polys/rings.py:998:20 error[invalid-argument-type] Argument to bound method `PolyElement._try_rsub_ground` is incorrect: Argument type `Er@PolyElement & PolyElement[Unknown] & ~PolyElement[Er@PolyElement]` does not satisfy upper bound `PolyElement[Er@PolyElement]` of type variable `Self`
- sympy/solvers/solveset.py:3167:15 error[no-matching-overload] No overload of bound method `Set.subs` matches arguments
trio (https://github.com/python-trio/trio)
- src/trio/_core/_tests/test_run.py:2913:16 error[unresolved-attribute] Object of type `BaseException` has no attribute `message`
+ src/trio/_core/_tests/test_run.py:2913:16 error[unresolved-attribute] Attribute `message` is not defined on `BaseException` in union `Unknown | BaseException`
websockets (https://github.com/aaugustin/websockets)
- src/websockets/asyncio/connection.py:481:45 error[invalid-argument-type] Argument to bound method `Protocol.send_text` is incorrect: Expected `bytes | bytearray | memoryview[int]`, found `bytes | bytearray | (Iterable[str | bytes | bytearray | memoryview[int]] & Top[memoryview[Unknown]]) | memoryview[int]`
+ src/websockets/asyncio/connection.py:481:45 error[invalid-argument-type] Argument to bound method `Protocol.send_text` is incorrect: Expected `bytes | bytearray | memoryview[int]`, found `bytes | bytearray | memoryview[str | bytes | bytearray | memoryview[int]] | memoryview[int]`
- src/websockets/sync/connection.py:492:47 error[invalid-argument-type] Argument to bound method `Protocol.send_binary` is incorrect: Expected `bytes | bytearray | memoryview[int]`, found `bytes | bytearray | (Iterable[str | bytes | bytearray | memoryview[int]] & Top[memoryview[Unknown]]) | memoryview[int]`
+ src/websockets/sync/connection.py:492:47 error[invalid-argument-type] Argument to bound method `Protocol.send_binary` is incorrect: Expected `bytes | bytearray | memoryview[int]`, found `bytes | bytearray | memoryview[str | bytes | bytearray | memoryview[int]] | memoryview[int]`
werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/_internal.py:42:12 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `(Any & Top[dict[Unknown, Unknown]]) | dict[str, Any] | (Request & Top[dict[Unknown, Unknown]])`
- src/werkzeug/middleware/shared_data.py:121:23 error[invalid-assignment] Object of type `ItemsView[object, object]` is not assignable to `Mapping[str, str | tuple[str, str]] | Iterable[tuple[str, str | tuple[str, str]]]`
+ src/werkzeug/middleware/shared_data.py:121:23 error[invalid-assignment] Object of type `ItemsView[str, str | tuple[str, str]] | ItemsView[tuple[str, str | tuple[str, str]], Unknown]` is not assignable to `Mapping[str, str | tuple[str, str]] | Iterable[tuple[str, str | tuple[str, str]]]`
xarray (https://github.com/pydata/xarray)
- xarray/core/dataset.py:4714:48 error[unsupported-operator] Operator `<` is not supported between objects of type `int` and `object`
- xarray/namedarray/core.py:843:59 error[invalid-argument-type] Argument to bound method `ChunkManagerEntrypoint.rechunk` is incorrect: Expected `tuple[tuple[int, ...], ...] | tuple[int, ...]`, found `(Mapping[Any, str | int | tuple[int, ...] | None] & float*) | str | tuple[int, ...] | ... omitted 4 union elements`
+ xarray/namedarray/core.py:843:59 error[invalid-argument-type] Argument to bound method `ChunkManagerEntrypoint.rechunk` is incorrect: Expected `tuple[tuple[int, ...], ...] | tuple[int, ...]`, found `str | tuple[int, ...] | (Mapping[Any, str | int | tuple[int, ...] | None] & float*) | ... omitted 4 union elements`
- xarray/namedarray/core.py:862:59 error[invalid-argument-type] Argument to bound method `ChunkManagerEntrypoint.from_array` is incorrect: Expected `tuple[tuple[int, ...], ...]`, found `(Mapping[Any, str | int | tuple[int, ...] | None] & float*) | str | tuple[int, ...] | ... omitted 5 union elements`
+ xarray/namedarray/core.py:862:59 error[invalid-argument-type] Argument to bound method `ChunkManagerEntrypoint.from_array` is incorrect: Expected `tuple[tuple[int, ...], ...]`, found `str | tuple[int, ...] | (Mapping[Any, str | int | tuple[int, ...] | None] & float*) | ... omitted 4 union elements`
- xarray/structure/combine.py:69:57 error[invalid-argument-type] Argument to function `_infer_tile_ids_from_nested_list` is incorrect: Expected `NestedSequence[Unknown]`, found `object`
+ xarray/structure/combine.py:69:57 error[invalid-argument-type] Argument to function `_infer_tile_ids_from_nested_list` is incorrect: Expected `NestedSequence[T@_infer_tile_ids_from_nested_list]`, found `T@_infer_tile_ids_from_nested_list | NestedSequence[T@_infer_tile_ids_from_nested_list]`
zulip (https://github.com/zulip/zulip)
- scripts/lib/supervisor.py:51:12 error[not-subscriptable] Cannot subscript object of type `object` with no `__getitem__` method
- scripts/lib/supervisor.py:52:23 error[not-subscriptable] Cannot subscript object of type `object` with no `__getitem__` method
- zerver/lib/push_notifications.py:608:23 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["android_devices"]` on object of type `Top[dict[Unknown, Unknown]]`
- zerver/lib/push_notifications.py:609:23 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["apple_devices"]` on object of type `Top[dict[Unknown, Unknown]]`
- zerver/lib/push_notifications.py:615:20 error[invalid-argument-type] Argument to function `sorted` is incorrect: Argument type `object` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
- zerver/lib/push_notifications.py:616:20 error[invalid-argument-type] Argument to function `sorted` is incorrect: Argument type `object` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
- zerver/lib/push_notifications.py:651:33 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["expected_end_timestamp"]` on object of type `Top[dict[Unknown, Unknown]]`
- zerver/lib/remote_server.py:479:50 error[not-subscriptable] Cannot subscript object of type `object` with no `__getitem__` method
- zerver/lib/validator.py:275:24 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `object` on object of type `Top[dict[Unknown, Unknown]]`
- zerver/lib/validator.py:475:20 error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any]`, found `Top[dict[Unknown, Unknown]]`
- zerver/lib/validator.py:502:8 error[invalid-argument-type] Method `__getitem__` of type `bound method Top[dict[Unknown, Unknown]].__getitem__(key: Never, /) -> object` cannot be called with key of type `Literal["type"]` on object of type `Top[dict[Unknown, Unknown]]`
Merging this PR will improve performance by 5.38%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | ty_micro[mixed_typed_dict_union_copy] |
121.2 ms | 115 ms | +5.38% |
Tip
Curious why this is faster? Use the CodSpeed MCP and ask your agent.
Comparing david/isinstance-filtering (885be27) with main (fce9727)
Footnotes
-
24 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
isinstance narrowing using specialization filteringisinstance narrowing via union filtering
4cc2f56 to
8548567
Compare
isinstance narrowing via union filteringisinstance narrowing for generic classes
|
|
||
| def narrow_union_with_unrelated_classes(value: Item | OpenItem | Sequence[int]) -> None: | ||
| if isinstance(value, list): | ||
| reveal_type(value) # revealed: (OpenItem & list[Unknown]) | list[int] |
There was a problem hiding this comment.
Notably, we still build proper intersection types like OpenItem & list[Unknown] here where other type checkers just infer list[int]. I think this should be addressed separately.
| from typing import Callable | ||
|
|
||
| def call_with_args(y: object): | ||
| if isinstance(y, Callable): |
There was a problem hiding this comment.
Note that this means that our default behavior here for isinstance(.., Callable) will be different from a callable(..) check, which always uses the top materialization. This was previously discussed as an acceptable compromise, if I understood our discussion correctly.
There was a problem hiding this comment.
I don't remember details of that discussion. I think this is probably acceptable for now, though I think ideally these would have the same semantics. I guess in order to do that we would need to special-case callable (so the top materialization of its return type can depend on the strict-narrowing setting) rather than just patching typeshed...
There was a problem hiding this comment.
Previous discussion here: #26797 (comment). I will open a ticket to address this as a follow-up.
carljm
left a comment
There was a problem hiding this comment.
Looks really good, thank you! Really not that much new code to implement this. Lots of new tests (and unfortunately a lot of ongoing maintenance burden to double-write some kinds of tests.)
Question I hate to ask: should we double-run ecosystem checks now, once in gradual mode and once in strict mode? Otherwise it seems it will be very hard to see the effects of changes to e.g. intersection simplification or disjointness on strict mode.
We have some docs on "how to make ty strict" -- should we add a reference to this setting there?
| from typing import Callable | ||
|
|
||
| def call_with_args(y: object): | ||
| if isinstance(y, Callable): |
There was a problem hiding this comment.
I don't remember details of that discussion. I think this is probably acceptable for now, though I think ideally these would have the same semantics. I guess in order to do that we would need to special-case callable (so the top materialization of its return type can depend on the strict-narrowing setting) rather than just patching typeshed...
| def __init__(self, value: T) -> None: ... | ||
|
|
||
| def box_with_default[T: str = str](value: Box[T] | T) -> Box[T]: | ||
| def box_with_default[T: Item = Item](value: Box[T] | T) -> Box[T]: |
There was a problem hiding this comment.
Why did this PR change that (without the @final)?
| #[derive(Hash, PartialEq, Debug, Eq, Clone, get_size2::GetSize, salsa::SalsaValue)] | ||
| struct Conjunctions<'db> { | ||
| conjuncts: SmallVec<[Type<'db>; 2]>, | ||
| conjuncts: SmallVec<[NarrowingOperation<'db>; 2]>, |
There was a problem hiding this comment.
I suspect we could do better with memory here (presuming most narrowings are not generic-filterings), but the overall impact seems low, so I don't think that needs to be done in this PR.
There was a problem hiding this comment.
I'm not really sure what you have in mind here, but if you have concrete ideas, or a feeling that we should improve this, it would be great if you could open a follow-up ticket.
There was a problem hiding this comment.
Oh, I just meant that the extra bit we track here might bump up the size here (though I haven't checked the sizeof Type vs NarrowingOperation, not sure if there's a niche available in Type that it can take advantage of), and if most narrowings are not generic filterings, we could avoid that by keeping the representation in a sidecar form rather than inline with every conjunct. But I don't think this is even worth a follow-up issue, it doesn't look that significant in the memory report.
Yes, that seems like a good idea. I started a discussion with the team.
Edit: I see we have a section that goes beyond what pyright/mypy do. I will update that and various other parts in the documentation as a follow up. |
|
there was a single (expected) change in the ecosystem report after pushing these updates. |
Summary
This PR introduces a new
ty.analysis.strict-generic-narrowingoption that controls howisinstanceandissubclassnarrowing works for unspecialized generic classes. When this option is set totrue, we use the top materialization of the generic class (e.g.Top[list[Unknown]]). This is the current behavior onmainand the sound way to doisinstancenarrowing with generic classes. When the option is set tofalse(the new default), we switch to an unsound mode that is intended to help users migrate from other type checkers.In this non-strict mode, we intersect with the
Unknown-specialization of the generic class. For example,x: objectis narrowed toobject & list[Unknown] = list[Unknown]afterisinstance(x, list). If the type ofxalready contains a specialization oflist, or a generic base oflist, we narrow to the correspondinglistspecialization instead. For example,x: Sequence[int]is narrowed tolist[int], andx: Mapping[str, int]is narrowed todict[str, int]afterisinstance(x, dict).We also add a special case for
TypedDicts here: When starting from aTypedDicttype, and narrowing viaisinstance(.., dict)(orMapping,MutableMapping, ..), we simply preserve the previousTypedDicttype.We also apply those settings to class patterns in
matchstatements, resolving this comment: astral-sh/ty#3676 (comment)strict-generic-narrowing = true(current behavior onmain)strict-generic-narrowing = false(gradual / non-strict, new default behavior)closes astral-sh/ty#3476 (basically asks for exactly this feature)
closes astral-sh/ty#3890 (we support all of these use cases as intended by the user)
closes astral-sh/ty#3676 (in the new default mode, the original use case is supported, in strict mode, we need to implement the intersection simplifications which are tracked in astral-sh/ty#1824)
closes astral-sh/ty#2843 (we support the original use case now. we could keep this issue open if we really want to support this in strict mode as well?)
closes astral-sh/ty#3477 (already closed, but directly asks for a mode like this)
also related: astral-sh/ty#1130 (we have special handling for TypedDicts here, but we probably still want to solve this for strict mode)
Previously considered alternatives
isinstance/issubclassnarrowing using gradual intersections #26472 Intersecting with the gradualUnknownspecialization. The problem here was that this introduces too much graduality. When starting from a fully static type likeSequence[int], we would getSequence[int] & Sequence[Unknown] = Sequence[int & Unknown]after anisinstance(..., Sequence)check. Iterating over that type would yield elements of typeint & Unknown, which is too permissive.isinstancenarrowing using transient top materializations #26797 Intersecting with transient top materializations. The idea here was to still intersect withTop[C[Unknown]], but then remove thatTopmaterialization after the intersection type had been simplified. This solved the problem withSequence[..]above, because now we created the intersection typeSequence[int] & Top[Sequence[Unknown]] = Sequence[int] & Sequence[object] = Sequence[int & object] = Sequence[int]which was still fully static. However, this still caused problems when invariant generics were involved. For example, starting withSequence[int]and narrowing usingisinstance(.., list)would lead toSequence[int] & Top[list[Unknown]]. We showed that this type is equivalent toTop[list[int & Unknown]], but that didn't solve the problem that iterating over that type after removing theTopmaterialization still yielded elements of typeint & Unknown.isinstancenarrowing using taggedobject/Nevertypes #26848 isinstance narrowing using taggedobject/Nevertypes. This approach followed the suggestion in Specially marked top/bottom types for betterTypeIsnarrowing experience ty#3375. The idea was to create types that act likeobject/Neverin intersection simplification, but likeUnknownelsewhere. One problem was that this didn't really address the problem of invariant generics. For those, we were still forced to use a specialTop*[..]materialization that would tell us: this type came from a non-strict isinstance narrowing and it should produceobject*/Never*types when methods/attributes are accessed on this type. So for theSequence[int] / isinstance(.., list)example, we would still createSequence[int] & Top*[list[Unknown]], but the advantage was that we now created the intersectionint & object*when iterating over that type. Since this simplified toint, it seemed like the problem from above was solved. However, introducing those two magical types didn't feel very satisfactory. And we still didn't match the behavior of other type checkers. When narrowing fromobjectusingisinstance(..., list), we would createTop*[list[Unknown]], whereas other type checkers simply inferredlist[Unknown]. And there were also more subtle problems where merging a type likeobject*with another type in a control-flow join would createobject* | Other = object*and therefore lose precision.Test plan
New and updated Markdown tests
Ecosystem
Looks good. There are some cases where
TypedDicttypes "survive" a negativeisinstance(.., dict)check, but I think that's astral-sh/ty#1130. Gradual mode doesn't do anything differently in negative branches.PR_27308_ECOSYSTEM_SUMMARY.md (the egglog case was resolved since then)