GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Spec/Conformance: subtyping callables with non-constant parameter mapping. · Issue #2224 · python/typing

Spec/Conformance: subtyping callables with non-constant parameter mapping. #2224

New issue
Copy link
New issue
Copy link
Open
Open
Spec/Conformance: subtyping callables with non-constant parameter mapping.#2224
Copy link
Labels
topic: typing specFor improving the typing specFor improving the typing spec

Description

@randolf-scholz
randolf-scholz
opened on Mar 22, 2026
Issue body actions

Consider the example below, which errors with all tested type checkers (mypy/pyright/ty/pyrefly):

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  # ❌️ type checkers error here.

I believe from a pure type theory POV, this assignment should be legal, because all legal arguments to Make are also legal arguments to make_impl. The spec phrases it in the same spirit:

A callable type B is assignable to a callable type A if the return type of B is assignable to the return type of A and the input 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.

And I couldn't find anything else in https://typing.python.org/en/latest/spec/callables.html#assignability-rules-for-callables that would disallow this assignment.

It seems the type-checkers try to match the KEYWORD_OR_POSITIONAL parameters by name, which is incorrect. Make has 3 legal call signatures:

  1. Make(float, float)
  2. Make(float, upper=float)
  3. Make(lower=float, upper=float)

and all these 3 call signatures are supported by make_impl, but the parameter mapping is not constant:

  1. make_impl(float, float) -> {lower:string_or_lower, upper:lower}
  2. make_impl(float, upper=float) -> {lower:string_or_lower, upper:upper}
  3. make_impl(lower=float, upper=float) -> {lower:lower, upper:upper}

So either the spec should demand a constant parameter mapping, or this example should be added to the conformance tests.

Activity

  1. randolf-scholz
    changed the title [-]Spec/Conformance: subtyping callable with positional-only parameters with defaults.[/-] [+]Spec/Conformance: subtyping callables with non-constant parameter mapping.[/+] on Mar 22, 2026
  2. srittau
    added
    topic: typing specFor improving the typing specFor improving the typing spec
    on Mar 22, 2026
  3. BHUVANSH855 commented on Apr 7, 2026

    @BHUVANSH855
    BHUVANSH855
    on Apr 7, 2026
    Contributor
    More actions

    Hi @srittau @randolf-scholz,

    I’ve opened a PR to clarify this behavior.

    The spec currently doesn’t define whether parameter mapping must be consistent. This PR clarifies that non-constant parameter mappings are not assignable, aligning the spec with existing type checker behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: typing specFor improving the typing specFor improving the typing spec

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.