Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NoReturn a SpecialForm #6290

Merged
merged 2 commits into from
Nov 13, 2021
Merged

Make NoReturn a SpecialForm #6290

merged 2 commits into from
Nov 13, 2021

Conversation

JelleZijlstra
Copy link
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
Member Author

Thanks!

@github-actions

This comment has been minimized.

@erictraut
Copy link
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
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
Contributor

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

@JelleZijlstra
Copy link
Member Author

Thanks for the very quick fix! CI passes now.

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Mar 9, 2022

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