Skip to content

fix(constraints): disambiguate overloaded callables using ParamSpec hints - #22546

Open
DrSkyle wants to merge 2 commits into
python:masterfrom
DrSkyle:fix/to-thread-optional-arg-regression-22515
Open

DrSkyle wants to merge 2 commits into
python:masterfrom
DrSkyle:fix/to-thread-optional-arg-regression-22515

Conversation

@DrSkyle

@DrSkyle DrSkyle commented Nov 24, 2026

Copy link
Copy Markdown

Fixes #22515.

Changes

During two-sided inference, mypy now uses call-site arguments to select the matching overload for a callable or callable protocol with a ParamSpec. infer_constraints_for_callable saves the call-site parameter hints, and infer_against_overloaded uses them to expand the ParamSpec before matching overloads.

Added testParamSpecTwoSidedOverloadDisambiguation to cover the regression with asyncio.create_task(asyncio.to_thread(shutil.rmtree, ...)).

Verification

  • ParamSpec and inference-context suites: 237 passed.
  • Regression test run on its own: passed.
  • ruff check, ruff format --check, and the mypy self-check passed.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

[regression] Optional argument of callable passed to to_thread missing in call to to_thread

1 participant