Skip to content

Union[X, NoReturn] isn't properly narrowed to X #11876

@tusharsadhwani

Description

@tusharsadhwani
Contributor
from typing import Union, NoReturn

def func() -> Union[str, NoReturn]:
    return 'test'

func().lower()

Here, Unoin[str, NoReturn] should effectively be treated as the same as str. But mypy doesn't seem to do that.

$ mypy code.py
code.py:6: error: Item "NoReturn" of "Union[str, NoReturn]" has no attribute "lower"
Found 1 error in 1 file (checked 1 source file)

More information in this discussion page: python/typing#994 (comment)

Activity

gschaffner

gschaffner commented on Oct 14, 2022

@gschaffner
Contributor

This appears to be fixed as of Mypy 0.940.

hauntsaninja

hauntsaninja commented on Oct 14, 2022

@hauntsaninja
Collaborator

Thanks, this was fixed in #11996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gschaffner@hauntsaninja@tusharsadhwani

        Issue actions

          `Union[X, NoReturn]` isn't properly narrowed to `X` · Issue #11876 · python/mypy