Skip to content
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

Merged
merged 9 commits into from
Oct 9, 2024
Merged

documentation for TypeIs #17821

merged 9 commits into from
Oct 9, 2024

Conversation

chelseadz
Copy link

Fixes #17156

As requested in the issue, added documentation for the desired behaviour of TypeIs.

Copy link
Contributor

@Hnasar Hnasar left a comment

Choose a reason for hiding this comment

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

nice!

docs/source/type_narrowing.rst Outdated Show resolved Hide resolved
docs/source/type_narrowing.rst Outdated Show resolved Hide resolved
docs/source/type_narrowing.rst Show resolved Hide resolved
docs/source/type_narrowing.rst Outdated Show resolved Hide resolved
@chelseadz chelseadz closed this Sep 26, 2024
@chelseadz chelseadz reopened this Sep 26, 2024
Copy link
Collaborator

@JukkaL JukkaL 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 the PR! Overall looks great, just a few comments. It would be good to have this included in the mypy 1.12 release.

TypeIs
------

Mypy supports TypeIs (:pep:`754`).
Copy link
Collaborator

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.



While both TypeIs and TypeGuard allow you to define custom type narrowing
functions, they differ in important ways:
Copy link
Collaborator

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.


def process(x: Any) -> None:
if is_instance_of(x, int):
reveal_type(x) # Revealed type is 'int' or any int subclass
Copy link
Collaborator

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.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks!

@JukkaL JukkaL merged commit 9e24b56 into python:master Oct 9, 2024
2 checks passed
JukkaL pushed a commit that referenced this pull request Oct 9, 2024
Fixes #17156.

As requested in the issue, added documentation for the desired behaviour
of TypeIs.
@chelseadz chelseadz deleted the documentTypeIs branch October 10, 2024 01:16
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.

Document TypeIs
3 participants