[ty] Infer lambda parameter types with Callable type context#24317
Open
ibraheemdev wants to merge 5 commits intomainfrom
Open
[ty] Infer lambda parameter types with Callable type context#24317ibraheemdev wants to merge 5 commits intomainfrom
Callable type context#24317ibraheemdev wants to merge 5 commits intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.72%. The percentage of expected errors that received a diagnostic held steady at 82.85%. The number of fully passing files held steady at 74/132. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 40 | 0 |
unresolved-attribute |
28 | 0 | 0 |
invalid-argument-type |
19 | 0 | 4 |
unused-type-ignore-comment |
2 | 15 | 0 |
unsupported-operator |
14 | 0 | 0 |
not-subscriptable |
13 | 0 | 0 |
invalid-assignment |
4 | 1 | 4 |
invalid-return-type |
0 | 4 | 0 |
| Total | 80 | 60 | 8 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
Raw diff (97 changes)
Expression (https://github.com/cognitedata/Expression)
+ expression/extra/parser.py:160:56 error[invalid-argument-type] Argument is incorrect: Expected `Never`, found `Parser[_A@choice]`
- tests/test_result.py:535:26 error[invalid-argument-type] Argument to bound method `or_else_with` is incorrect: Expected `(Literal["original error"], /) -> Result[Any, Literal["original error"]]`, found `(error: Literal["original error"]) -> Result[Any, str]`
+ tests/test_result.py:535:26 error[invalid-argument-type] Argument to bound method `or_else_with` is incorrect: Expected `(Literal["original error"], /) -> Result[Any, Literal["original error"]]`, found `(error: Literal["original error"]) -> Result[Any, Literal["new error from original error"]]`
PyWinCtl (https://github.com/Kalmat/PyWinCtl)
- src/pywinctl/_main.py:831:49 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:832:60 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:833:56 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:835:56 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:836:67 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:837:63 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:838:57 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:839:66 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:840:71 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- src/pywinctl/_main.py:841:98 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
attrs (https://github.com/python-attrs/attrs)
- tests/test_cmp.py:364:23 error[invalid-argument-type] Argument to function `cmp_using` is incorrect: Expected `((Any, Any, /) -> bool) | None`, found `(a: Any, b: Any) -> _NotImplementedType | (bool & Unknown)`
+ tests/test_cmp.py:364:23 error[invalid-argument-type] Argument to function `cmp_using` is incorrect: Expected `((Any, Any, /) -> bool) | None`, found `(a: Any, b: Any) -> _NotImplementedType | (bool & Any)`
cki-lib (https://gitlab.com/cki-project/cki-lib)
- cki_lib/owners.py:319:16 error[invalid-return-type] Return type does not match returned value: expected `None`, found `str`
core (https://github.com/home-assistant/core)
+ homeassistant/bootstrap.py:631:9 error[invalid-argument-type] Argument to bound method `exception` is incorrect: Expected `None | bool | tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] | BaseException`, found `tuple[type[BaseException], BaseException | None, TracebackType | None]`
+ homeassistant/components/fronius/sensor.py:611:36 error[invalid-argument-type] Argument to function `max` is incorrect: Argument type `str | int | float | None` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
+ homeassistant/components/fronius/sensor.py:611:36 error[invalid-argument-type] Argument to function `max` is incorrect: Expected `Literal[0]`, found `StateType`
+ homeassistant/components/fronius/sensor.py:620:36 error[unsupported-operator] Operator `-` is not supported between objects of type `Literal[0]` and `StateType`
+ homeassistant/components/fronius/sensor.py:637:36 error[invalid-argument-type] Argument to function `max` is incorrect: Argument type `str | int | float | None` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
+ homeassistant/components/fronius/sensor.py:637:36 error[invalid-argument-type] Argument to function `max` is incorrect: Expected `Literal[0]`, found `StateType`
+ homeassistant/components/fronius/sensor.py:646:36 error[unsupported-operator] Operator `-` is not supported between objects of type `Literal[0]` and `StateType`
+ homeassistant/components/fronius/sensor.py:663:36 error[invalid-argument-type] Argument to function `max` is incorrect: Argument type `str | int | float | None` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
+ homeassistant/components/fronius/sensor.py:663:36 error[invalid-argument-type] Argument to function `max` is incorrect: Expected `Literal[0]`, found `StateType`
+ homeassistant/components/fronius/sensor.py:673:36 error[unsupported-operator] Operator `-` is not supported between objects of type `Literal[0]` and `StateType`
+ homeassistant/components/gardena_bluetooth/sensor.py:62:48 error[invalid-assignment] Object of type `(x: T@GardenaBluetoothSensorEntityDescription | None) -> T@GardenaBluetoothSensorEntityDescription | None` is not assignable to `(T@GardenaBluetoothSensorEntityDescription | None, /) -> SensorRawType`
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/internal/settings/symbol_db.py:25:83 error[unresolved-attribute] Object of type `Env` has no attribute `includes`
+ tests/debugging/exploration/_config.py:81:19 error[unresolved-attribute] Object of type `Env` has no attribute `output_file`
+ tests/debugging/exploration/_config.py:81:46 error[unresolved-attribute] Object of type `Env` has no attribute `output_file`
+ tests/debugging/exploration/_config.py:87:28 error[unresolved-attribute] Object of type `Env` has no attribute `conservative`
+ tests/debugging/exploration/_config.py:89:26 error[unresolved-attribute] Object of type `Env` has no attribute `conservative`
+ tests/internal/bytecode_injection/framework_injection/_config.py:59:19 error[unresolved-attribute] Object of type `Env` has no attribute `output_file`
+ tests/internal/bytecode_injection/framework_injection/_config.py:59:46 error[unresolved-attribute] Object of type `Env` has no attribute `output_file`
+ ddtrace/internal/settings/dynamic_instrumentation.py:123:97 error[unresolved-attribute] Object of type `Env` has no attribute `redacted_types`
+ ddtrace/internal/settings/dynamic_instrumentation.py:124:12 error[unresolved-attribute] Object of type `Env` has no attribute `redacted_types`
egglog-python (https://github.com/egraphs-good/egglog-python)
- python/egglog/exp/array_api.py:2031:71 error[invalid-argument-type] Argument to bound method `if_` is incorrect: Expected `() -> NDArray`, found `() -> Value | Unknown | Int`
+ python/egglog/exp/array_api.py:2031:71 error[invalid-argument-type] Argument to bound method `if_` is incorrect: Expected `() -> NDArray`, found `() -> Value | Int | i64 | ... omitted 5 union elements`
+ python/egglog/exp/array_api.py:2031:79 error[invalid-argument-type] Method `__getitem__` of type `bound method Vec[Int].__getitem__(index: i64 | int) -> Int` cannot be called with key of type `Int` on object of type `Vec[Int]`
+ python/egglog/exp/array_api.py:2031:79 error[invalid-argument-type] Method `__getitem__` of type `bound method Vec[Value].__getitem__(index: i64 | int) -> Value` cannot be called with key of type `Int` on object of type `Vec[Value]`
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/wrapper/_implementations.py:1735:52 error[invalid-assignment] Object of type `((x: str | None) -> object) | (((str | None, /) -> str | None) & ~Top[Mapping[Unknown, object]])` is not assignable to `(str | None, /) -> str | None`
- src/hydra_zen/wrapper/_implementations.py:1736:59 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
ignite (https://github.com/pytorch/ignite)
+ tests/ignite/handlers/test_checkpoint.py:272:92 error[unresolved-attribute] Attribute `score` is not defined on `State` in union `Unknown | State`
+ tests/ignite/handlers/test_checkpoint.py:348:89 error[unresolved-attribute] Attribute `score` is not defined on `State` in union `Unknown | State`
meson (https://github.com/mesonbuild/meson)
+ mesonbuild/backend/ninjabackend.py:1942:81 error[unresolved-attribute] Attribute `startswith` is not defined on `None` in union `str | None`
mypy (https://github.com/python/mypy)
+ mypy/semanal.py:7195:50 error[invalid-argument-type] Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Divergent, ...]`, found `object`
+ mypy/semanal.py:7196:44 error[unresolved-attribute] Object of type `object` has no attribute `type`
+ mypy/semanal.py:7208:23 error[unresolved-attribute] Object of type `object` has no attribute `type`
optuna (https://github.com/optuna/optuna)
+ optuna/samplers/_tpe/_erf.py:117:72 error[invalid-assignment] Object of type `list[((ndarray[Unknown, dtype[Any]], /) -> ndarray[Unknown, dtype[Any]]) | ((x: ndarray[Unknown, dtype[Any]]) -> float64 | Any)]` is not assignable to `list[(ndarray[Unknown, dtype[Any]], /) -> ndarray[Unknown, dtype[Any]]]`
+ tests/visualization_tests/test_contour.py:523:26 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_edf.py:172:33 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_parallel_coordinate.py:780:33 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_param_importances.py:273:26 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_param_importances.py:295:26 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_pareto_front.py:333:13 error[invalid-argument-type] Argument to function `_get_pareto_front_info` is incorrect: Expected `((FrozenTrial, /) -> Sequence[int | float]) | None`, found `(t: FrozenTrial) -> Unknown | int | float`
+ tests/visualization_tests/test_pareto_front.py:333:31 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_pareto_front.py:351:32 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_pareto_front.py:351:45 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_pareto_front.py:351:58 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_rank.py:615:26 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
+ tests/visualization_tests/test_slice.py:402:26 error[not-subscriptable] Cannot subscript object of type `None` with no `__getitem__` method
paasta (https://github.com/yelp/paasta)
- paasta_tools/setup_prometheus_adapter_config.py:983:12 error[invalid-return-type] Return type does not match returned value: expected `PrometheusAdapterConfig`, found `dict[str, list[PrometheusAdapterRule | UnspecializedTypeVar]]`
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/base/methods.py:397:48 error[unsupported-operator] Operator `<=` is not supported between two objects of type `Hashable`
+ pandas/tests/extension/base/methods.py:410:49 error[unsupported-operator] Operator `<=` is not supported between two objects of type `Hashable`
+ pandas/tests/extension/base/methods.py:446:47 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/extension/base/methods.py:450:48 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/extension/base/methods.py:454:49 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/series/methods/test_combine.py:12:46 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/series/methods/test_combine.py:16:51 error[invalid-argument-type] Argument to function `min` is incorrect: Argument type `Hashable` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
+ pandas/tests/series/methods/test_combine.py:16:54 error[invalid-argument-type] Argument to function `min` is incorrect: Argument type `Hashable` does not satisfy upper bound `SupportsDunderLT[Any] | SupportsDunderGT[Any]` of type variable `SupportsRichComparisonT`
+ pandas/tests/series/methods/test_combine.py:24:44 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/series/methods/test_combine.py:35:46 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/extension/test_categorical.py:127:48 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
+ pandas/tests/extension/test_categorical.py:134:49 error[unsupported-operator] Operator `+` is not supported between two objects of type `Hashable`
- pandas/tests/frame/methods/test_map.py:101:46 error[invalid-argument-type] Argument to bound method `map` is incorrect: Expected `(Any, /) -> Any`, found `(x: Any, y) -> Unknown`
+ pandas/tests/frame/methods/test_map.py:101:46 error[invalid-argument-type] Argument to bound method `map` is incorrect: Expected `(Any, /) -> Any`, found `(x: Any, y) -> Any`
- pandas/tseries/holiday.py:412:20 error[invalid-return-type] Return type does not match returned value: expected `DatetimeIndex`, found `Index`
pycryptodome (https://github.com/Legrandin/pycryptodome)
+ lib/Crypto/SelfTest/Protocol/test_KDF.py:141:52 error[invalid-argument-type] Argument to function `new` is incorrect: Expected `bytes | bytearray | memoryview[int]`, found `int`
pydantic (https://github.com/pydantic/pydantic)
- pydantic/_internal/_mock_val_ser.py:137:5 error[invalid-assignment] Object of type `MockValSer[Unknown]` is not assignable to attribute `validator` of type `SchemaValidator | PluggableSchemaValidator`
+ pydantic/_internal/_mock_val_ser.py:137:5 error[invalid-assignment] Object of type `MockValSer[SchemaValidator | PluggableSchemaValidator]` is not assignable to attribute `validator` of type `SchemaValidator | PluggableSchemaValidator`
- pydantic/_internal/_mock_val_ser.py:143:5 error[invalid-assignment] Object of type `MockValSer[Unknown]` is not assignable to attribute `serializer` of type `SchemaSerializer`
+ pydantic/_internal/_mock_val_ser.py:143:5 error[invalid-assignment] Object of type `MockValSer[SchemaSerializer]` is not assignable to attribute `serializer` of type `SchemaSerializer`
- pydantic/_internal/_mock_val_ser.py:176:5 error[invalid-assignment] Object of type `MockValSer[Unknown]` is not assignable to attribute `__pydantic_validator__` of type `SchemaValidator | PluggableSchemaValidator`
+ pydantic/_internal/_mock_val_ser.py:176:5 error[invalid-assignment] Object of type `MockValSer[SchemaValidator | PluggableSchemaValidator]` is not assignable to attribute `__pydantic_validator__` of type `SchemaValidator | PluggableSchemaValidator`
- pydantic/_internal/_mock_val_ser.py:182:5 error[invalid-assignment] Object of type `MockValSer[Unknown]` is not assignable to attribute `__pydantic_serializer__` of type `SchemaSerializer`
+ pydantic/_internal/_mock_val_ser.py:182:5 error[invalid-assignment] Object of type `MockValSer[SchemaSerializer]` is not assignable to attribute `__pydantic_serializer__` of type `SchemaSerializer`
+ pydantic/main.py:110:81 error[invalid-assignment] Object of type `dict[str, ((model: BaseModel, name: str, val: Any) -> None) | ((model: BaseModel, name: str, val: Any) -> dict[str, Any] | tuple[dict[str, Any], dict[str, Any] | None, set[str]] | Any)]` is not assignable to `Mapping[str, (BaseModel, str, Any, /) -> None]`
rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/evm/node_inquirer.py:1393:21 error[invalid-argument-type] Argument to bound method `get_l1_fee` is incorrect: Expected `Literal[ChainID.OPTIMISM, ChainID.BASE, ChainID.SCROLL]`, found `Literal[ChainID.ETHEREUM, ChainID.OPTIMISM, ChainID.POLYGON_POS, ChainID.ARBITRUM_ONE, ChainID.BASE, ... omitted 5 literals]`
schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/dlang_codegen.py:440:50 error[unsupported-operator] Operator `&` is not supported between two objects of type `Sized`
static-frame (https://github.com/static-frame/static-frame)
- static_frame/test/unit/test_series.py:2681:65 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- static_frame/test/unit/test_store_zip.py:176:61 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ static_frame/test/unit/test_yarn.py:1676:53 error[unresolved-attribute] Attribute `size` is not defined on `tuple[Any, Any]` in union `Any | tuple[Any, Any]`
+ static_frame/test/unit/test_yarn.py:1691:41 error[unresolved-attribute] Attribute `size` is not defined on `tuple[Any, Any]` in union `Any | tuple[Any, Any]`
+ static_frame/test/unit/test_yarn.py:1696:37 error[unresolved-attribute] Attribute `size` is not defined on `tuple[Any, Any]` in union `Any | tuple[Any, Any]`
+ static_frame/test/unit/test_yarn.py:1712:53 error[unresolved-attribute] Attribute `size` is not defined on `tuple[Any, Any]` in union `@Todo | tuple[Any, Any]`
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/watcher/local_sources_watcher.py:242:72 error[invalid-assignment] Object of type `list[((ModuleType, /) -> list[str | None]) | ((m: ModuleType) -> list[Never] | list[str | None])]` is not assignable to `list[(ModuleType, /) -> list[str | None]]`
+ lib/streamlit/watcher/local_sources_watcher.py:267:18 error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[str | None]`, found `object`
sympy (https://github.com/sympy/sympy)
+ sympy/core/basic.py:787:33 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- sympy/matrices/matrixbase.py:2644:72 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
- sympy/matrices/matrixbase.py:2736:71 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
+ sympy/plotting/plot.py:104:28 error[not-subscriptable] Cannot subscript object of type `Basic` with no `__getitem__` method
+ sympy/plotting/plot.py:104:52 error[not-subscriptable] Cannot subscript object of type `Basic` with no `__getitem__` method
+ sympy/tensor/array/array_derivatives.py:52:52 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
vision (https://github.com/pytorch/vision)
+ test/builtin_dataset_mocks.py:644:21 error[invalid-argument-type] Argument to function `create_image_folder` is incorrect: Expected `(int, /) -> str`, found `(idx: int) -> str | int | Unknown`
+ test/builtin_dataset_mocks.py:646:21 error[invalid-argument-type] Argument to function `create_image_folder` is incorrect: Expected `Sequence[int] | int | ((int, /) -> Sequence[int] | int) | None`, found `(idx: int) -> tuple[Literal[3], str | int | Unknown, str | int | Unknown]`2583e1a to
7eda4ee
Compare
Merging this PR will degrade performance by 5.31%
Performance Changes
Comparing Footnotes
|
0026c70 to
8804a2c
Compare
ffee1da to
dd15d65
Compare
dd15d65 to
37b6769
Compare
37b6769 to
3b5d296
Compare
Member
Author
|
I haven't looked too closely at the ecosystem report but those diagnostics look expected, as this PR increases our type inference coverage quite significantly where we would previously infer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves #22633 to infer the use of lambda parameters in a lambda body with type context, e.g.,
Unlike other definitions, lambda parameter types cannot be determined purely syntactically in semantic indexing. Instead, they depend on the inferred type of the lambda to access its parameter types. Unfortunately, this makes lambda inference cyclic, as the body of the lambda depends on the outer lambda type, and there is no obvious way of splitting out inference of the lambda parameter types from its return type.
To avoid initiating cycles on the entire scope containing the lambda, this PR introduces a new inference query — statement-level inference. Statements are a minimal unit of code that encapsulate any internal type context. This makes them very useful to infer a given sub-expression "naturally" without having to provide any external type context. There are other places where we currently rely on scope-level inference for this purpose (e.g., see
infer_complete_scope_types, the current implementation of #23761, and the discussion in astral-sh/ty#3124). Note that statement-level inference is not perfectly fine-grained, e.g., the test expression of anifstatement does not require external type context and is independent from its body, so statement-level inference may lead to unnecessarily large cycles, but having the unit of code being generalized to an AST structure allows us to avoid the need for such special cases, but this can always change in the future.Additionally, many statements are simply wrappers around definitions or standalone expressions, so we can avoid extra salsa allocations in the common case.