-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
PEP 484: Add NoReturn type #218
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
Conversation
pep-0484.txt
Outdated
The ``NoReturn`` type | ||
--------------------- | ||
|
||
``typing`` module provides a special type ``NoReturn`` to annotate functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a "The" before typing
is required here.
pep-0484.txt
Outdated
|
||
The ``NoReturn`` type is only valid as a return annotation of functions, | ||
and considered an error if appears in other positions:: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if appears -> if it appears
pep-0484.txt
Outdated
from typing import List, NoReturn | ||
|
||
# All of the following are errors | ||
def bad1(x: Noreturn) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noreturn -> NoReturn
@DimitrisJim Thanks, fixed! |
pep-0484.txt
Outdated
from typing import NoReturn | ||
|
||
def stop() -> NoReturn: | ||
raise Exception('no way') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this RuntimeException? raise Exception
is such an anti-pattern I don't ever want to see it. :-)
pep-0484.txt
Outdated
def stop() -> NoReturn: | ||
raise Exception('no way') | ||
|
||
Such return annotation is used in ``typeshed`` stubs for functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such return -> The NoReturn
(mostly to avoid using "such" twice in one sentence :-).
Also, drop "in typeshed".
pep-0484.txt
Outdated
if x > 0: | ||
return x | ||
stop() | ||
return 'whatever works' # No error reported by checkers that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this debatable. Why would you have dead code that doesn't type-check? (Though maybe we've had this discussion already? I don't feel strongly about it, just wonder if maybe PEP 484 isn't the place to require this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how mypy behaves (in fact, and in documentation). I softened the formulation in the new commit (as well as fixed two other things).
I don't have a strong opinion here either, but I think it maybe worth keeping mypy and PEP "in sync".
LGTM. Let's see if @markshannon has anything to say. |
@markshannon, calling twice? |
I'll just merge it. |
As discussed in python/typing#165, it is time to document the
NoReturn
type.@gvanrossum Please take a look when you will have time.