Clarify callable assignability to require consistent parameter mapping#2247
Clarify callable assignability to require consistent parameter mapping#2247BHUVANSH855 wants to merge 5 commits intopython:mainfrom
Conversation
carljm
left a comment
There was a problem hiding this comment.
I don't think this is the direction we should go in the spec. It seems to me that the requirement for a constant mapping is a quality-of-implementation issue. What the spec already describes is the intended and desired behavior; implementations just aren't fully implementing it. The spec should not prohibit a type checker from attempting to do better.
…r mapping" This reverts commit e01d065.
|
Thanks for the feedback @carljm, That makes sense — I understand that the spec describes the intended behavior, even if current type checkers don't fully support it. I've updated the PR to remove the spec change and instead added a conformance test capturing this scenario, so the gap between the spec and current implementations is made explicit. Kindly review it again |
Fixes #2224
The current typing spec states that a callable type B is assignable to a callable type A if B accepts all possible combinations of arguments that A accepts. However, it does not explicitly define whether the mapping between parameters must remain consistent across different call patterns.
In practice, all major type checkers (mypy, pyright, etc.) reject cases where parameter mapping is non-constant, even if all valid calls are technically accepted.
This PR clarifies the spec by stating that callable assignability requires a consistent parameter mapping. If arguments map to different parameters depending on how they are passed (positional vs keyword), the callable is not considered assignable.
This aligns the spec with existing type checker behavior and resolves the ambiguity highlighted in the issue.