microsoft / microsoft/pyright

Setting `()` to `Union`, which means no type arguments doesn't get error

Open
#11,261 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

*Memo:
- pyright test.py
- pyright 1.1.408
- Python 3.14.0

The error message caused by [Union](https://docs.python.org/3/library/typing.html#typing.Union) with one type says as shown below:

```python
from typing import Union

v: Union[int] # Error
```

> error: Union requires two or more type arguments (reportInvalidTypeArguments

But setting `()` to `Union`, which means no type arguments doesn't get error as shown below:

```python
from typing import Union

v: Union[()] # No error
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the shown test.py examples using pyright 1.1.408. Compare the diagnostics for Union[int] and Union[()], then trace the Union type-argument validation; done means Union[()] reports the invalid zero-argument case consistently with Union[int].

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.