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

[Doc] mypy skips check function return None as a common issue #4594

Merged
merged 5 commits into from Mar 27, 2018

Conversation

Projects
None yet
3 participants
@hvnsweeting
Contributor

hvnsweeting commented Feb 20, 2018

When I got problem (#4587) , I looked into the doc and noticed "common issues" and FAQ but non of these helped me. Add this as I think it is a common issue when new user evaluating using mypy, they might write simple functions to see how the tool work.

@hvnsweeting hvnsweeting changed the title from Add mypy skip check return None as a common issue to [Doc] mypy skips check function return None as a common issue Feb 20, 2018

@ethanhs

This comment has been minimized.

Collaborator

ethanhs commented Feb 20, 2018

Hm, this is already pretty well documented at https://mypy.readthedocs.io/en/latest/kinds_of_types.html#the-type-of-none-and-optional-types, though it may be that a section in common issues is needed as well.

@gvanrossum

This comment has been minimized.

Member

gvanrossum commented Feb 20, 2018

I actually like adding such things to "common issues" or "FAQ" since sometimes users are overwhelmed by the structure of the docs. (Up to a point -- a FAQ with 100s of sections is also overwhelming. :-)

I think the language needs to be cleaned up a bit, and --strict-optional is no longer experimental (in fact it is slated to become the default in the future, perhaps in the next half year).

@@ -51,6 +51,11 @@ flagged as an error.
If you don't know what types to add, you can use ``Any``, but beware:
- **The function returns ``None`` value but it was annotated as having a return

This comment has been minimized.

@ethanhs

ethanhs Feb 26, 2018

Collaborator

I would re-word this to something like "A function annotated as non-Optional returns None and mypy doesn't complain".

@@ -51,6 +51,11 @@ flagged as an error.
If you don't know what types to add, you can use ``Any``, but beware:
- **The function returns ``None`` value but it was annotated as having a return
type of other types.** By default, ``None`` value is considered compatible
with everything. See :ref:`optional` for details and an experimental mode

This comment has been minimized.

@ethanhs

ethanhs Feb 26, 2018

Collaborator

... for details on strict optional checking, which allows mypy to check None values precisely, and will soon become default.

@@ -51,6 +51,12 @@ flagged as an error.
If you don't know what types to add, you can use ``Any``, but beware:
- **A function annotated as non-optional returns ``None`` and mypy doesn't
complain** By default, ``None`` value is considered compatible

This comment has been minimized.

@ethanhs

ethanhs Feb 26, 2018

Collaborator

"None value" > "None" or put "the" before None, since you are talking about a definite noun.

@ethanhs

Thanks for adding this!

@ethanhs

One more small nit and this should be good to merge. Thanks @hvnsweeting!

@@ -85,6 +85,18 @@ flagged as an error.
clarity about the latter use ``--follow-imports=error``. You can
read up about these and other useful flags in :ref:`command-line`.
- **A function annotated as returning non-optional type but returns ``None``

This comment has been minimized.

@ethanhs

ethanhs Mar 27, 2018

Collaborator

Hm, perhaps this should be:

annotated as returning a non-optional type returns None...

This comment has been minimized.

@gvanrossum

gvanrossum Mar 27, 2018

Member

You can make this small edit on the web yourself and then merge. No need to wait for OP.

@ethanhs ethanhs merged commit 7d4a0c1 into python:master Mar 27, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@hvnsweeting hvnsweeting deleted the hvnsweeting:return-non-common-issue branch Mar 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment