Skip to content

Make NoReturn a SpecialForm - #6290

Merged
hauntsaninja merged 2 commits into
masterfrom
JelleZijlstra-patch-2
Nov 13, 2021
Merged

hauntsaninja merged 2 commits into
masterfrom
JelleZijlstra-patch-2

Conversation

@JelleZijlstra

Copy link
Copy Markdown
Member

This is consistent with the runtime definition: https://github.com/python/cpython/blob/main/Lib/typing.py#L434.

The previous definition was wrong; NoReturn is not and should not be equivalent to None. This fixes an issue in pyanalyze where it was interpreting NoReturn as equivalent to None.

cc @erictraut in case this affects pyright. mypy-primer will tell us what mypy thinks about it.

This is consistent with the runtime definition: https://github.com/python/cpython/blob/main/Lib/typing.py#L434.

The previous definition was wrong; NoReturn is not and should not be equivalent to None. This fixes an issue in pyanalyze where it was interpreting NoReturn as equivalent to None.

cc @erictraut in case this affects pyright. mypy-primer will tell us what mypy thinks about it.
@JelleZijlstra

Copy link
Copy Markdown
Member Author

Thanks!

@github-actions

This comment has been minimized.

@erictraut

Copy link
Copy Markdown
Contributor

I've made the necessary changes in pyright, and I'll be publishing a new version within the next few hours. We can then update your PR to point to the new version, which should eliminate the CI errors.

@erictraut

Copy link
Copy Markdown
Contributor

I've published pyright 1.1.187, which fixes this issue. Typeshed currently uses 1.1.184. If you update this version (in both workflows/tests.yml and tests/pyright_test.py) within your PR, the CI errors should disappear.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra

Copy link
Copy Markdown
Member Author

Thanks for the very quick fix! CI passes now.

@KotlinIsland

KotlinIsland commented Mar 9, 2022 •

Copy link
Copy Markdown
Contributor

I think the original author's intent would be much more accurately described with:

NoReturn: TypeAlias = Union[()] # "<nothing>" 

😳😳😳😳😳😳😳😳😳😳😳😳

This works correctly at type time:

from typing import TypeAlias, Union

Never: TypeAlias = Union[()]

a: Never = 1  # error: Incompatible types in assignment (expression has type "int", variable has type <nothing>)

But not at runtime 😁. Good thing it's just a stub.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants