From e01d06547a107a015332fa5d7577418b4ee357f8 Mon Sep 17 00:00:00 2001 From: Bhuvansh855 Date: Wed, 8 Apr 2026 02:46:55 +0530 Subject: [PATCH 1/3] Clarify callable assignability to require consistent parameter mapping --- docs/spec/callables.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index a4028aae8..93338e947 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -453,7 +453,7 @@ a function within a type expression. The syntax is Parameters specified using ``Callable`` are assumed to be positional-only. The ``Callable`` form provides no way to specify keyword-only parameters, -or default argument values. For these use cases, see the section on +or default argument values. For these use cases, see the section on `Callback protocols`_. Meaning of ``...`` in ``Callable`` @@ -581,6 +581,24 @@ signature of ``B`` accepts all possible combinations of arguments that the input signature of ``A`` accepts. All of the specific assignability rules described below derive from this general rule. +Parameter Mapping Consistency +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +For a callable type ``B`` to be :term:`assignable` to a callable type ``A``, +the mapping between parameters in ``A`` and ``B`` should be +consistent across all valid call signatures. + +In particular, each argument accepted by ``A`` should correspond +to a single, well-defined parameter in ``B``, regardless of whether +arguments are passed positionally or by keyword. + +If the correspondence between parameters in ``A`` and ``B`` varies depending +on how arguments are provided, then the callable types are not considered +assignable. + +For example, if different valid call patterns for ``A`` result in arguments +being mapped to different parameters in ``B``, this constitutes a +non-constant parameter mapping and is not assignable. Parameter types ^^^^^^^^^^^^^^^ From cfdd96c1eb737045c2fc2bf7a3973289800dc9ca Mon Sep 17 00:00:00 2001 From: Bhuvansh855 Date: Wed, 8 Apr 2026 12:23:32 +0530 Subject: [PATCH 2/3] Revert "Clarify callable assignability to require consistent parameter mapping" This reverts commit e01d06547a107a015332fa5d7577418b4ee357f8. --- docs/spec/callables.rst | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index 93338e947..a4028aae8 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -453,7 +453,7 @@ a function within a type expression. The syntax is Parameters specified using ``Callable`` are assumed to be positional-only. The ``Callable`` form provides no way to specify keyword-only parameters, -or default argument values. For these use cases, see the section on +or default argument values. For these use cases, see the section on `Callback protocols`_. Meaning of ``...`` in ``Callable`` @@ -581,24 +581,6 @@ signature of ``B`` accepts all possible combinations of arguments that the input signature of ``A`` accepts. All of the specific assignability rules described below derive from this general rule. -Parameter Mapping Consistency -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -For a callable type ``B`` to be :term:`assignable` to a callable type ``A``, -the mapping between parameters in ``A`` and ``B`` should be -consistent across all valid call signatures. - -In particular, each argument accepted by ``A`` should correspond -to a single, well-defined parameter in ``B``, regardless of whether -arguments are passed positionally or by keyword. - -If the correspondence between parameters in ``A`` and ``B`` varies depending -on how arguments are provided, then the callable types are not considered -assignable. - -For example, if different valid call patterns for ``A`` result in arguments -being mapped to different parameters in ``B``, this constitutes a -non-constant parameter mapping and is not assignable. Parameter types ^^^^^^^^^^^^^^^ From da6c64b5dd934f22d3794245dc9247657eeb2063 Mon Sep 17 00:00:00 2001 From: Bhuvansh855 Date: Wed, 8 Apr 2026 12:26:35 +0530 Subject: [PATCH 3/3] Add conformance test for callable subtyping with non-constant parameter mapping --- .../tests/callables_non_constant_mapping.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 conformance/tests/callables_non_constant_mapping.py diff --git a/conformance/tests/callables_non_constant_mapping.py b/conformance/tests/callables_non_constant_mapping.py new file mode 100644 index 000000000..788a83d40 --- /dev/null +++ b/conformance/tests/callables_non_constant_mapping.py @@ -0,0 +1,29 @@ +""" +Tests callable assignability with non-constant parameter mapping. + +Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#assignability-rules-for-callables + +This case is currently rejected by type checkers but appears to be +allowed by the typing spec, since all valid calls are accepted. +""" + +from typing import Protocol + + +class Interval: ... + + +class Make(Protocol): + def __call__(self, /, lower: float, upper: float) -> Interval: ... + + +def make_impl( + string_or_lower: str | float | None = None, + /, + lower: float | None = None, + upper: float | None = None, +) -> Interval: ... + + +def test() -> None: + f: Make = make_impl # OK