python / python/mypy

`reveal_locals` is hella inconsistent / top level variables not listed / narrowed type inconsistent with `reveal_type`

Open
#11,956 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

a: int
b = 1
if isinstance(a, bool):
    reveal_locals()  # "b: int", I would expect "a: bool, b: int"
    reveal_type(a)  # "a: bool" ✔
    
def foo(a: int) -> None:
    b: int
    reveal_locals()  # "a: int, b: int", this is correct, but inconsistent with top level
    reveal_type(a)
a: int = 1
reveal_locals() # nothing 😥

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 locating the implementation and tests for reveal_locals(), then compare its handling of module and function scopes with reveal_type(). Done means the examples consistently include narrowed a values and initialized top-level variables in the reveal_locals() output.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.