-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
documentation for TypeIs #17821
documentation for TypeIs #17821
Conversation
for more information, see https://pre-commit.ci
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.
nice!
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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.
Thanks for the PR! Overall looks great, just a few comments. It would be good to have this included in the mypy 1.12 release.
docs/source/type_narrowing.rst
Outdated
TypeIs | ||
------ | ||
|
||
Mypy supports TypeIs (:pep:`754`). |
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.
The PEP number is 742.
docs/source/type_narrowing.rst
Outdated
|
||
|
||
While both TypeIs and TypeGuard allow you to define custom type narrowing | ||
functions, they differ in important ways: |
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.
The paragraph above is a duplicate.
docs/source/type_narrowing.rst
Outdated
|
||
def process(x: Any) -> None: | ||
if is_instance_of(x, int): | ||
reveal_type(x) # Revealed type is 'int' or any int subclass |
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.
Nit: The revealed type is just 'int', not any subclass.
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.
Thanks!
Fixes #17156. As requested in the issue, added documentation for the desired behaviour of TypeIs.
Fixes #17156
As requested in the issue, added documentation for the desired behaviour of TypeIs.