python / python/mypy

Condition can't be inferred, unable to merge overloads

Open
#19,516 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report

I don't know how to describe it, but mypy throws the Condition can't be inferred, unable to merge overloads error

To Reproduce

Gist URL: https://gist.github.com/mypy-play/db2fda335634c93b6c2b044b98fd5c71
Playground URL: https://mypy-play.net/?mypy=master&python=3.13&gist=db2fda335634c93b6c2b044b98fd5c71

def any_function() -> None: ...


if 'Any expression':

    @any_function
    def _(): ...


def _(): ...

Expected Behavior

Works fine, at least without this misc

Actual Behavior

❯ mypy mypy.py 
mypy.py:4: error: Condition can't be inferred, unable to merge overloads  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.17.0 (compiled: yes)
  • Mypy command-line flags: mypy mypy.py
  • Mypy configuration options from mypy.ini (and other config files): nope
  • Python version used: 3.10.18

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

Start by running the minimal reproducer from the issue with mypy 1.17.0 and compare the diagnostic around the conditional and overload merging. Trace where Condition can't be inferred, unable to merge overloads is emitted, then add regression coverage showing that this example no longer reports the misc error while preserving relevant overload diagnostics.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.