Skip to content

WIP: try to cache inner contexts of overloads #19408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Jul 8, 2025

Improves #14978 and marginally improves nested overloads checking in general. This is not ready for review, but I would appreciate any in-progress feedback on the idea itself.

If I understand correctly, this change should not change any behavior at all: infer_arg_types_in_empty_context is almost pure.

The full change I attempted halved colour check time but caused (seemingly) false negatives. Let's try minimal scope first.

Another very similar problem arises when checking overloaded binary operations (like in #14978), they do not translate directly into a series of overloads check but repeat the whole process for every node instead. I'm working on this.

This comment has been minimized.

@sterliakov sterliakov changed the title WIP: try to cache inner contexts of overloads and ops WIP: try to cache inner contexts of overloads Jul 8, 2025
Copy link
Contributor

github-actions bot commented Jul 8, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/server/database/query_components.py:182: error: Cannot determine type of "scheduled_flow_runs"  [has-type]
- src/prefect/server/database/query_components.py:190: error: Cannot determine type of "scheduled_flow_runs"  [has-type]
- src/prefect/server/database/query_components.py:190: error: Cannot determine type of "join_criteria"  [has-type]
- src/prefect/server/database/query_components.py:196: error: Cannot determine type of "scheduled_flow_runs"  [has-type]
- src/prefect/server/database/query_components.py:197: error: Cannot determine type of "scheduled_flow_runs"  [has-type]

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/datatypes/cast.py:119: error: Value of type "DataType" is not indexable  [index]
- ibis/expr/operations/arrays.py:254: error: "Range" has no attribute "start"  [attr-defined]
- ibis/expr/operations/arrays.py:254: error: "Range" has no attribute "stop"  [attr-defined]
- ibis/expr/api.py:1202: error: Too few arguments for "Interval"  [call-arg]
- ibis/expr/api.py:1202: error: Argument 1 to "Interval" has incompatible type "str"; expected "bool"  [arg-type]
- ibis/backends/sql/__init__.py:515: error: Item "Iterable[str]" of "str | Iterable[str]" has no attribute "format"  [union-attr]
- ibis/backends/clickhouse/tests/test_datatypes.py:263: error: Argument "scale" to "Timestamp" has incompatible type "int"; expected "Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None"  [arg-type]
- ibis/backends/mysql/tests/test_client.py:69: error: Argument "scale" to "Timestamp" has incompatible type "int | None"; expected "Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None"  [arg-type]

kornia (https://github.com/kornia/kornia)
- kornia/utils/draw.py:381: error: Cannot determine type of "b_i"  [has-type]
- kornia/utils/draw.py:381: error: Cannot determine type of "c_i"  [has-type]
- kornia/utils/draw.py:388: error: Cannot determine type of "w_i"  [has-type]
- kornia/utils/draw.py:388: error: Cannot determine type of "device"  [has-type]
- kornia/utils/draw.py:388: error: Cannot determine type of "dtype_p"  [has-type]

optuna (https://github.com/optuna/optuna)
+ optuna/visualization/_intermediate_values.py:95: error: Unused "type: ignore" comment  [unused-ignore]

dedupe (https://github.com/dedupeio/dedupe)
+ dedupe/canopy_index.py:86: error: Unused "type: ignore" comment  [unused-ignore]

altair (https://github.com/vega/altair)
- altair/utils/_vegafusion_data.py:230: error: Argument 1 to "handle_row_limit_exceeded" has incompatible type "Any | None"; expected "int"  [arg-type]

freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/templates/FreqaiExampleStrategy.py:245: error: Unsupported left operand type for & ("tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | <18 more items>, ...]")  [operator]
- freqtrade/templates/FreqaiExampleStrategy.py:255: error: Unsupported left operand type for & ("tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | <18 more items>, ...]")  [operator]

@sterliakov sterliakov closed this Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant