-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Adds better type narrowing docs #11088
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
Adds better type narrowing docs #11088
Conversation
docs/source/type_narrowing.rst
Outdated
|
||
.. note:: | ||
|
||
Narrowing type for some impossible state will be treated as an error. |
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 isn't generally true, e.g. not even with --strict
, I think you need --warn-unreachable
for 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.
Could also maybe mention the assert_never
trick here though
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 awesome. I made a bunch of small wording changes. The only substantive comment here is about --warn-unreachable
which we need to be a little careful about. E.g., there's some discussion of it here: https://mypy.readthedocs.io/en/stable/common_issues.html#unreachable-code
@hauntsaninja thanks a lot for your help! I've added a note about |
Thank you! |
List of changed:
casts
intotype-narrowing
TypeGuard
type there, it fits perfectlyRefs #11014
CC @hauntsaninja