python / python/mypy

Setting two arguments to `Optional` within `reveal_type()` doesn't get error

Open
#20,432 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

*Memo:
mypy test.py
mypy 1.19.1
Python 3.14.0
Windows 11

Setting two arguments to Optional properly gets the error as shown below:

from typing import Optional

          # ↓↓↓  ↓↓↓
v: Optional[int, str] = 100 # Error

error: Optional[...] must have exactly one type argument

But, setting two arguments to Optional within reveal_type() doesn't get the error as shown below so the error should occur:

from typing import Optional, reveal_type

                   # ↓↓↓  ↓↓↓
reveal_type(Optional[int, str]) # No error

note: Revealed type is "typing._SpecialForm"

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 from the provided test.py snippets with mypy 1.19.1 on Python 3.14. Start by tracing how reveal_type() handles Optional[int, str] compared with an annotation context. Done means the reveal_type() expression reports the same invalid-argument error as the annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.