python / python/mypy

(🐞) `reveal_type` on a lambda parameter from an overloaded higher order function shows two results

Open
#11,953 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Here the type of value is an non-inferred int, and there is only one usage of reveal_type, yet mypy is outputting two results (one of which is incorrect)

reveal_locals() shows two entries for value, but one being None not Any.

from typing import overload, Callable

@overload
def bar() -> None: ...
@overload
def bar(fn: Callable[[int], object]) -> None: ...

def bar(fn: object=1) -> None: ...
    

bar(lambda value: reveal_type(value))
bar(lambda value: reveal_locals())
main.py:11: note: Revealed type is "Any"
main.py:11: note: Revealed type is "builtins.int"
main.py:12: note: Revealed local types are:
main.py:12: note:     value: None
main.py:12: note:     value: builtins.int
Success: no issues found in 1 source file

Without removing duplicate messages you get this:

test.py:12: note: Revealed local types are:
test.py:12: note:     value: None
test.py:12: note: Revealed local types are:
test.py:12: note:     value: builtings.int
  • Cause of #5879

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 overloaded higher-order function example from main.py and the duplicate reveal_locals output shown for test.py. Start by tracing how reveal_type and reveal_locals handle the two lambda parameter types, then verify that one usage produces one correct result and no duplicate local-type messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, 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.