Skip to content

Conversation

@vincent-prz
Copy link
Contributor

@vincent-prz vincent-prz commented Dec 15, 2018

Fixes #5037

Add a paragrah to explain there are 2 ways to make the typechecker
understand that an optional is not None: use a if condition or an
assert.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks for a PR! I have one comment.

# First way: with an if condition
if x is not None:
print(x.upper())
# Second way: with an assert statement
Copy link
Member

Choose a reason for hiding this comment

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

These are not just two ways. They are semantically different. The cheat sheet should say something like:

# If it still may be None sometimes, use an if-statement
...
# If it can never be None (e.g. due to some invariants), use an assert
...

Add a paragrah to explain how to indicate to the type checker that an
Optional value is not None: with an if statement, or an assert
(depending upon the situation)
@vincent-prz vincent-prz force-pushed the document-assertions-for-optionals branch from 8ae71c7 to ca95897 Compare December 22, 2018 12:41
@vincent-prz
Copy link
Contributor Author

@ilevkivskyi I have addressed your comment. Does this look good to you ? Thanks!

@ilevkivskyi ilevkivskyi merged commit 9a3fa64 into python:master Dec 22, 2018
@ilevkivskyi
Copy link
Member

Thanks!

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.

2 participants