[ty] Fix TODO for meta-type of intersections#24761
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownsphinx
prefect
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
7 | 2 | 7 |
unused-type-ignore-comment |
10 | 3 | 0 |
unknown-argument |
12 | 0 | 0 |
too-many-positional-arguments |
11 | 0 | 0 |
invalid-return-type |
3 | 1 | 0 |
invalid-assignment |
1 | 0 | 0 |
missing-argument |
1 | 0 | 0 |
no-matching-overload |
1 | 0 | 0 |
not-iterable |
0 | 1 | 0 |
possibly-missing-attribute |
1 | 0 | 0 |
| Total | 47 | 7 | 7 |
Raw diff (61 changes)
bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/embed/standalone.py:287:28 error[too-many-positional-arguments] Too many positional arguments to `Model.__init__`: expected 1, got 2
+ src/bokeh/embed/standalone.py:287:28 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
core (https://github.com/home-assistant/core)
- homeassistant/runner.py:234:13 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `Mapping[str, object] | None`, found `tuple[type[@Todo], Any, Any]`
+ homeassistant/runner.py:234:13 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `Mapping[str, object] | None`, found `tuple[type[Unknown], Any, Any]`
- homeassistant/runner.py:234:13 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `bool`, found `tuple[type[@Todo], Any, Any]`
+ homeassistant/runner.py:234:13 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `bool`, found `tuple[type[Unknown], Any, Any]`
- homeassistant/runner.py:234:13 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `int`, found `tuple[type[@Todo], Any, Any]`
+ homeassistant/runner.py:234:13 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `int`, found `tuple[type[Unknown], Any, Any]`
- homeassistant/runner.py:242:9 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `Mapping[str, object] | None`, found `tuple[type[@Todo], Any, Any]`
+ homeassistant/runner.py:242:9 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `Mapping[str, object] | None`, found `tuple[type[Unknown], Any, Any]`
- homeassistant/runner.py:242:9 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `bool`, found `tuple[type[@Todo], Any, Any]`
+ homeassistant/runner.py:242:9 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `bool`, found `tuple[type[Unknown], Any, Any]`
- homeassistant/runner.py:242:9 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `int`, found `tuple[type[@Todo], Any, Any]`
+ homeassistant/runner.py:242:9 error[invalid-argument-type] Argument to bound method `Logger.error` is incorrect: Expected `int`, found `tuple[type[Unknown], Any, Any]`
discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/commands/core.py:1183:16 warning[possibly-missing-attribute] Attribute `__cog_name__` may be missing on object of type `type[CogT@Command] & ~<class 'NoneType'>`
+ discord/ui/view.py:952:17 error[invalid-assignment] Invalid subscript assignment with key of type `Pattern[str]` and value of type `type[Item[Any]] & type[DynamicItem[object]]` on object of type `dict[Pattern[str], type[DynamicItem[Item[Any]]]]`
graphql-core (https://github.com/graphql-python/graphql-core)
+ src/graphql/language/visitor.py:229:43 error[invalid-argument-type] Argument is incorrect: Expected `Location | None`, found `Any | Node`
+ src/graphql/language/visitor.py:229:43 error[invalid-argument-type] Argument is incorrect: Expected `Location | None`, found `Any | Node`
+ src/graphql/language/visitor.py:229:43 error[invalid-argument-type] Argument is incorrect: Expected `Location | None`, found `Any | Node`
koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/namedtuple.py:130:43 error[invalid-argument-type] Argument to function `signature` is incorrect: Expected `(...) -> Any`, found `type[_NTT@NamedTupleValidator]`
mitmproxy (https://github.com/mitmproxy/mitmproxy)
- test/mitmproxy/proxy/tutils.py:354:25 error[invalid-argument-type] Method `__getitem__` of type `bound method dict[Command, type[CommandCompleted]].__getitem__(key: Command, /) -> type[CommandCompleted]` cannot be called with key of type `type[@Todo]` on object of type `dict[Command, type[CommandCompleted]]`
+ test/mitmproxy/proxy/tutils.py:354:25 error[invalid-argument-type] Method `__getitem__` of type `bound method dict[Command, type[CommandCompleted]].__getitem__(key: Command, /) -> type[CommandCompleted]` cannot be called with key of type `type[Command]` on object of type `dict[Command, type[CommandCompleted]]`
operator (https://github.com/canonical/operator)
- ops/model.py:1908:69 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/dtypes/concat.py:126:17 error[unknown-argument] Argument `axis` does not match any known parameter of bound method `ExtensionArray._concat_same_type`
+ pandas/core/sorting.py:629:37 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/rows.py:137:16 error[invalid-return-type] Return type does not match returned value: expected `RowMaker[tuple[object, ...] & NamedTupleLike]`, found `bound method type[NamedTupleLike]._make(iterable: Iterable[Any]) -> NamedTupleLike`
+ psycopg/psycopg/rows.py:145:12 error[invalid-return-type] Return type does not match returned value: expected `type[tuple[object, ...]] & type[NamedTupleLike]`, found `<class 'Row'>`
+ psycopg/psycopg/types/composite.py:514:12 error[invalid-return-type] Return type does not match returned value: expected `type[tuple[object, ...]] & type[NamedTupleLike]`, found `<class '<unknown>'>`
rotki (https://github.com/rotki/rotki)
+ rotkehlchen/tasks/historical_balances.py:592:36 error[missing-argument] No argument provided for required parameter `group_identifier` of `HistoryBaseEntry.__init__`
+ rotkehlchen/tasks/historical_balances.py:593:17 error[unknown-argument] Argument `tx_ref` does not match any known parameter of `HistoryBaseEntry.__init__`
+ rotkehlchen/tasks/historical_balances.py:593:17 error[invalid-argument-type] Argument to `OnchainEvent.__init__` is incorrect: Expected `Never`, found `object`
+ rotkehlchen/tasks/historical_balances.py:603:17 error[unknown-argument] Argument `counterparty` does not match any known parameter of `HistoryBaseEntry.__init__`
+ rotkehlchen/tasks/historical_balances.py:604:17 error[unknown-argument] Argument `address` does not match any known parameter of `HistoryBaseEntry.__init__`
+ rotkehlchen/tasks/historical_balances.py:604:17 error[invalid-argument-type] Argument to `OnchainEvent.__init__` is incorrect: Expected `None`, found `object`
scipy (https://github.com/scipy/scipy)
+ scipy/sparse/_index.py:54:43 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
+ scipy/sparse/_index.py:54:43 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
+ scipy/sparse/_index.py:54:50 error[unknown-argument] Argument `shape` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:54:50 error[unknown-argument] Argument `shape` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:54:67 error[unknown-argument] Argument `dtype` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:54:67 error[unknown-argument] Argument `dtype` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:56:43 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
+ scipy/sparse/_index.py:56:43 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
+ scipy/sparse/_index.py:56:52 error[unknown-argument] Argument `shape` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:56:52 error[unknown-argument] Argument `shape` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:56:69 error[unknown-argument] Argument `dtype` does not match any known parameter of `object.__init__`
+ scipy/sparse/_index.py:56:69 error[unknown-argument] Argument `dtype` does not match any known parameter of `object.__init__`
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/python.py:271:27 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/config.py:708:45 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
+ sphinx/config.py:739:41 error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
+ sphinx/domains/std/__init__.py:1392:26 error[no-matching-overload] No overload of bound method `dict.get` matches arguments
static-frame (https://github.com/static-frame/static-frame)
- static_frame/core/index_hierarchy.py:2173:20 error[invalid-return-type] Return type does not match returned value: expected `int | integer[Any] | ndarray[Any, Any] | ... omitted 3 union elements`, found `list[int | integer[Any] | ndarray[Any, Any] | ... omitted 3 union elements]`
- static_frame/core/index_hierarchy.py:2173:51 error[not-iterable] Object of type `ndarray[tuple[object, ...], dtype[object]] & ~int & ~Top[integer[Any]] & ~IndexHierarchy & ~Top[list[Unknown]]` is not iterable
+ static_frame/core/index_hierarchy.py:2160:75 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:187:32 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:190:69 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:191:61 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:199:41 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:202:68 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:204:60 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:207:88 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:209:55 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/core/loc_map.py:210:40 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- static_frame/core/quilt.py:856:58 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- static_frame/core/quilt.py:862:46 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- static_frame/core/type_blocks.py:3360:39 error[invalid-argument-type] Method `__getitem__` of type `Overload[(key: ndarray[tuple[Any, ...], dtype[integer[Any] | numpy.bool[builtins.bool]]] | tuple[ndarray[tuple[Any, ...], dtype[integer[Any] | numpy.bool[builtins.bool]]], ...], /) -> ndarray[tuple[Any, ...], dtype[object]], (key: SupportsIndex | tuple[SupportsIndex, ...], /) -> Any, (key: SupportsIndex | slice[Any, Any, Any] | EllipsisType | ... omitted 5 union elements, /) -> ndarray[tuple[Any, ...], dtype[object]], (key: str, /) -> ndarray[tuple[object, ...], dtype[Any]], (key: list[str], /) -> ndarray[tuple[object, ...], Unknown]]` cannot be called with key of type `slice[Any, Any, Any]` on object of type `ndarray[tuple[object, ...], dtype[object]]`
- static_frame/core/type_blocks.py:3370:21 error[invalid-argument-type] Method `__getitem__` of type `Overload[(key: ndarray[tuple[Any, ...], dtype[integer[Any] | numpy.bool[builtins.bool]]] | tuple[ndarray[tuple[Any, ...], dtype[integer[Any] | numpy.bool[builtins.bool]]], ...], /) -> ndarray[tuple[Any, ...], dtype[object]], (key: SupportsIndex | tuple[SupportsIndex, ...], /) -> Any, (key: SupportsIndex | slice[Any, Any, Any] | EllipsisType | ... omitted 5 union elements, /) -> ndarray[tuple[Any, ...], dtype[object]], (key: str, /) -> ndarray[tuple[object, ...], dtype[Any]], (key: list[str], /) -> ndarray[tuple[object, ...], Unknown]]` cannot be called with key of type `tuple[slice[Any, Any, Any], slice[Any, Any, Any]]` on object of type `ndarray[tuple[object, ...], dtype[object]]`
+ static_frame/test/unit/test_quilt.py:2111:45 error[invalid-argument-type] Argument to bound method `Quilt._axis_tuple` is incorrect: Expected `(type[tuple[object, ...]] & type[NamedTupleLike]) | None`, found `<class 'tuple'>`
sympy (https://github.com/sympy/sympy)
+ sympy/physics/quantum/spin.py:1028:21 error[too-many-positional-arguments] Too many positional arguments to constructor `SpinState.__new__`: expected 3, got 484a4fa7 to
fd2fc0d
Compare
Ecosystem analysis (WIP)Here's a minimized version of the bokeh hits Detailsfrom typing import Any, Sequence
class Model: ...
def f(
models: Model | dict[str, Model],
x: dict[object, object],
y: list[str],
):
dict_type: type[dict[Any, Any]] = dict
if isinstance(models, dict):
# (Model & Top[dict[Unknown, Unknown]]) | dict[str, Model]
reveal_type(models)
# (type[Model] & type[Top[dict[Unknown, Unknown]]]) | type[dict[str, Model]]
reveal_type(models.__class__)
dict_type = models.__class__
# <class 'dict'> | (type[Model] & type[Top[dict[Unknown, Unknown]]]) | type[dict[str, Model]]
reveal_type(dict_type)
# error[no-matching-overload] No overload of `dict.__init__` matches arguments
# error[no-matching-overload] No overload of `dict.__init__` matches arguments
# error[too-many-positional-arguments] Too many positional arguments to `object.__init__`: expected 1, got 2
dict_type(zip(x.keys(), y))On This feels like yet another instance where our narrowing-via-intersections behaviour is strictly correct, but will likely be quite confusing for our users. Still, this behaviour is consistent with our behaviour elsewhere, so it's not really a bug in this PR. A minimized version of the from typing import NamedTuple, Callable, Any
def f[T: NamedTuple](x: type[T], y: NamedTuple) -> type[T]:
reveal_type(x) # type[T@f]
reveal_type(y) # tuple[object, ...] & NamedTupleLike
# error[invalid-assignment] Object of type `type[T@f]` is not assignable to `(...) -> Any`
z: Callable[..., Any] = x
return xThis is due to a bug in our intersection <-> Callable type relations. I tried to fix it in #24830, but it's nontrivial; I don't think fixing it should block this PR. An issue tracking it is astral-sh/ty#3612. The pandas hits look similar to the bokeh hits, and they already have The psycopg hits minimize to this: from typing import NamedTuple, Any, Sequence, Protocol
class RowMaker[Row: tuple[Any, ...]](Protocol):
def __call__(self, values: Sequence[Any], /) -> Row: ...
def namedtuple_row(namedtuple_cls: type[NamedTuple]) -> RowMaker[NamedTuple]:
# error[invalid-return-type] Return type does not match returned value: expected `RowMaker[tuple[object, ...] & NamedTupleLike]`, found `bound method type[NamedTupleLike]._make(iterable: Iterable[Any]) -> NamedTupleLike`
return namedtuple_cls._makeIf this PR is rebased on #24770, we get And a minimal repro of this that demonstrates the issue on from ty_extensions import Intersection
from typing import Self, reveal_type
class Bar:
def method(self) -> Self:
return self
class Foo: ...
def f(x: Intersection[Bar, Foo]):
reveal_type(x.method())I opened astral-sh/ty#3565 to track this. The many diagnostics going away on static-frame minimize to this: from typing import Hashable
def needs_slice(k: slice) -> None: ...
def f(key: Hashable) -> None:
if isinstance(key, int):
return
if key.__class__ is slice:
needs_slice(key)The diagnostics go away because from typing import Hashable
def f(x: Hashable):
y = type(x)
if y is slice:
reveal_type(x) |
fd2fc0d to
a68488b
Compare
## Summary A bunch of followup changes from #25422. Mostly triggered by using the skill for the first time to analyze the report in #24761. - Move ty-specific guidance from `AGENTS.md` to a new local `working-on-ty` skill. Link to the other ty-specific skills from that skill. - Add more keyword triggers to various skills so that agents are more likely to automatically figure out that a skill is appropriate (suggested by @dhruvmanila). - Add more guidance to the ecosystem-minimization skill (and tweak the script for setting up a primer project) so that agents are likely to reproduce results in a deterministic and helpful way. ## Test Plan I repeatedly ran `/review` with Codex on this until the only remaining issues were trivial.
a68488b to
aecee8e
Compare
Summary
Test Plan