Skip to content

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

Merged
merged 4 commits into from
Mar 17, 2017
Merged

Conversation

ilevkivskyi
Copy link
Member

As discussed in python/typing#165, it is time to document the NoReturn type.

@gvanrossum Please take a look when you will have time.

pep-0484.txt Outdated
The ``NoReturn`` type
---------------------

``typing`` module provides a special type ``NoReturn`` to annotate functions
Copy link
Contributor

@DimitrisJim DimitrisJim Mar 7, 2017

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::

Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noreturn -> NoReturn

@ilevkivskyi
Copy link
Member Author

@DimitrisJim Thanks, fixed!

pep-0484.txt Outdated
from typing import NoReturn

def stop() -> NoReturn:
raise Exception('no way')
Copy link
Member

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

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

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.)

Copy link
Member Author

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".

@gvanrossum
Copy link
Member

LGTM. Let's see if @markshannon has anything to say.

@ambv
Copy link
Contributor

ambv commented Mar 16, 2017

@markshannon, calling twice?

@gvanrossum
Copy link
Member

gvanrossum commented Mar 17, 2017

I'll just merge it.

@gvanrossum gvanrossum merged commit 881c6be into python:master Mar 17, 2017
@gvanrossum gvanrossum deleted the add-noreturn branch March 17, 2017 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants