KEMBAR78
Consider changing NoReturn to not be a bottom type · Issue #4116 · python/mypy · GitHub
Skip to content

Consider changing NoReturn to not be a bottom type #4116

@Wilfred

Description

@Wilfred

NoReturn being a bottom type leads to mypy accepting code that I would consider to be invalid.

For example, saving the result of a NoReturn function to a variable:

import sys
from typing import List
from mypy_extensions import NoReturn

def never_returns() -> NoReturn:
    sys.exit(1)

def foo() -> None:
    x = [] # type: List[int]
    x = never_returns()

If mypy infers a type of NoReturn on my function body, it seems that I can write anything as the return type without getting a type error:

def foo1() -> dict:
    raise Exception('oh dear')

def foo2() -> list:
    sys.exit(1)

I'm struggling to think of any example where NoReturn being a bottom type allows me to do things that I couldn't otherwise do.

What's the rationale? Would you be open to changing this?

Originally discussed in #4066.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions