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

Spec: Allow NoReturn to appear outside of function return type annotations #1558

Open
erictraut opened this issue Jan 2, 2024 · 6 comments
Labels
topic: documentation Documentation-related issues and PRs

Comments

@erictraut
Copy link
Collaborator

The typing spec currently states:

The NoReturn type is only valid as a return annotation of functions, and considered an error if it appears in other positions.

This is old language from the time when NoReturn was first added in PEP 484. Since then, we've added Never to the typing spec and indicated that Never and NoReturn are equivalent types. Even before Never was added, the assert_never function made use of NoReturn outside of a return annotation.

No type checker currently enforces that NoReturn appears only in return type annotations of functions. I'd like to propose that we simply delete that section of the spec. That would bring the spec into alignment with the current behavior of all four major type checkers.

@erictraut erictraut added the topic: documentation Documentation-related issues and PRs label Jan 2, 2024
@superbobry
Copy link

Should we also clearly state that NoReturn is deprecated in favor of Never to mirror the wording in the docs?

@erictraut
Copy link
Collaborator Author

Should we also clearly state that NoReturn is deprecated in favor of Never to mirror the wording in the docs?

I don't have a strong opinion one way or another about this, but I think that's a separate issue.

@superbobry
Copy link

It is related in my mind, since NoReturn is named so that it really only makes sense in function return types, and this issue is about lifting that limitation.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 2, 2024

Should we also clearly state that NoReturn is deprecated in favor of Never to mirror the wording in the docs?

The docs don't actually state that NoReturn is deprecated. They state that using NoReturn to express the concept of the bottom type is discouraged (because Never is a clearer name for the type when it's used as such). We don't have any plans to remove NoReturn from the typing module, and I wouldn't even call it soft-deprecated.

If you just want to use it as a return type to say that a function never returns (because it enters into an infinite loop or whatever), then the name NoReturn is pretty unproblematic, so there's no real reason to deprecate it

@JelleZijlstra
Copy link
Member

I would propose that the spec should state that Never and NoReturn should be treated as exact equivalents by type checkers. There are reasons to use one name over the other, but that's more of a style guide issue, not a spec issue.

@superbobry
Copy link

Thanks @AlexWaygood and @JelleZijlstra!

I agree that it makes sense to treat Never and NoReturn as equivalent. I would personally still prefer for Python to have just one spelling of the bottom type, but I'm not convinced the migration cost for users is justified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: documentation Documentation-related issues and PRs
Projects
None yet
Development

No branches or pull requests

4 participants