python / python/mypy

`partial` plugin does not handle overloads

Open
#17,585 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-overloads
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

it appears the new partial plugin added in mypy 1.11 doesn't properly handle overloads (and just picks the first one)

To Reproduce

import functools
from typing import assert_type, overload

@overload
def identity(x: int, *, p: str) -> int: ...
@overload
def identity(x: str, *, p: str) -> str: ...
def identity(x: int | str, *, p: str) -> int | str: return x


p = functools.partial(identity, p='hi')
assert_type(p(1), int)
assert_type(p('hi'), str)

Expected Behavior

(no errors)

Actual Behavior

$ mypy t.py 
t.py:13: error: Expression is of type "int", not "str"  [assert-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.11.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided functools.partial, overload, and assert_type example by running mypy t.py. Trace the partial plugin's handling of overloaded callables and add coverage for both int and str arguments. Done means the example reports no errors and preserves both inferred return types.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.