Skip to content

Comments

[red-knot] Check assignability for two callable types#16845

Merged
dhruvmanila merged 3 commits intomainfrom
dhruv/callable-assignability
Mar 22, 2025
Merged

[red-knot] Check assignability for two callable types#16845
dhruvmanila merged 3 commits intomainfrom
dhruv/callable-assignability

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Mar 19, 2025

Summary

Part of #15382

This PR adds support for checking the assignability of two general callable types.

This is built on top of #16804 by including the gradual parameters check and accepting a function that performs the check between the two types.

Test Plan

Update is_assignable_to.md with callable types section.

@dhruvmanila dhruvmanila added the ty Multi-file analysis & type inference label Mar 19, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2025

mypy_primer results

Changes were detected when running on open source projects
isort (https://github.com/pycqa/isort)
- error[lint:invalid-argument-type] /tmp/mypy_primer/projects/isort/isort/output.py:55:17: Object of type `(key) -> Unknown` cannot be assigned to parameter `key` of function `sort`; expected type `(str, /) -> Any | None`
- error[lint:invalid-argument-type] /tmp/mypy_primer/projects/isort/isort/output.py:66:17: Object of type `(key) -> Unknown` cannot be assigned to parameter `key` of function `sort`; expected type `(str, /) -> Any | None`
- error[lint:invalid-argument-type] /tmp/mypy_primer/projects/isort/isort/output.py:268:17: Object of type `(key) -> Unknown` cannot be assigned to parameter `key` of function `sort`; expected type `(str, /) -> Any | None`
- Found 81 diagnostics
+ Found 78 diagnostics

@dhruvmanila dhruvmanila force-pushed the dhruv/callable-subtype branch from 12ff6b9 to a519c2e Compare March 20, 2025 12:10
@dhruvmanila dhruvmanila force-pushed the dhruv/callable-assignability branch from e31af42 to 2c1d6cc Compare March 20, 2025 12:13
@dhruvmanila dhruvmanila force-pushed the dhruv/callable-subtype branch from a519c2e to 3b1e030 Compare March 21, 2025 03:23
Base automatically changed from dhruv/callable-subtype to main March 21, 2025 03:27
@dhruvmanila dhruvmanila force-pushed the dhruv/callable-assignability branch 2 times, most recently from a41c2e7 to daabad4 Compare March 21, 2025 07:57
@dhruvmanila dhruvmanila force-pushed the dhruv/callable-assignability branch from daabad4 to 24d3352 Compare March 21, 2025 08:00
@dhruvmanila
Copy link
Member Author

The ecosystem changes looks correct, they're all related to assigning a lambda expression to a function parameter that's annotated with typing.Callable.

@dhruvmanila dhruvmanila marked this pull request as ready for review March 21, 2025 10:47
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@dhruvmanila dhruvmanila merged commit 1cffb32 into main Mar 22, 2025
23 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/callable-assignability branch March 22, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants