Add lint against empty Union
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
From the documentation it indicates that Union must contain at least one item, however this doesn't seem to be implemented in mypy (and in fact, mypy seems to treat an empty union as NoReturn) -- the treating it as NoReturn is actually kinda cool, but probably not what was intended (?)
my twitch chat is telling me that pyright also considers Union[()] as NoReturn, maybe this just needs cpython documentation
To Reproduce
from typing import Union
def f() -> Union:
print('hello hello')
def g() -> Union[()]:
print('hello hello')
$ mypy --version
mypy 0.800
$ mypy t.py
t.py:3: error: Implicit return in function which does not return
t.py:6: error: Implicit return in function which does not return
Found 2 errors in 1 file (checked 1 source file)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Union and Union[()] reproducer in the issue and inspect how mypy reports the implicit returns; no source file or test is identified. First determine whether the intended fix is a mypy diagnostic or a CPython documentation change, then verify that the chosen outcome distinguishes an empty Union from the current NoReturn behavior.
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
- Needs clarification
- Newbie friendliness
- 35/100