Skip to content

Conversation

@ddfisher
Copy link
Contributor

@ddfisher ddfisher commented Jan 4, 2017

Adds mypy_extensions.NoReturn as an alias for None and changes the annotation of some standard functions which don't return. Mypy will soon understand that this indicates a function cannot return (which is important for the --warn-no-return flag, which we're considering enabling by default).

@ddfisher
Copy link
Contributor Author

ddfisher commented Jan 4, 2017

It looks like right now there's no good way to alias None (really NoneType).

@ambv
Copy link
Contributor

ambv commented Jan 4, 2017

This is rather because of mypy_extensions.py in Mypy master not containing NoReturn yet. Mypy doesn't even look at the stub. Land python/mypy#2637 and it should work.

@ddfisher
Copy link
Contributor Author

ddfisher commented Jan 4, 2017

It's actually the other way round: if there's a stub, mypy doesn't look at the corresponding .py file.

I worked around the aliasing issue here by using Union[None] (which mypy understands as a type) as the RHS of the alias.

@ambv ambv merged commit 2cb8e18 into master Jan 4, 2017
@ddfisher ddfisher deleted the noreturn branch January 4, 2017 21:39
@ambv
Copy link
Contributor

ambv commented Jan 4, 2017

Right, I thought there's something special going on about mypy_extensions, just like lib-typing over typing.pyi.

# Return type that indicates a function does not return.
# This type is equivalent to the None type, but the no-op Union is necessary to
# distinguish the None type from the None value.
NoReturn = Union[None]
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I understand this. NoReturn is different from the NoneType, the latter is a type with one value, while the former is a type with no values, a.k.a. "error type" or "bottom type". Maybe it would be better to write class NoReturn: ...?

@gvanrossum What do you think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intent is to not disrupt typecheckers that don't yet support this (as it's not yet part of PEP 484).

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.

4 participants