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

Modernizing guide: Mention TypeGuard/TypeIs #1887

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/guides/modernizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,16 @@ Update your imports to use the new locations::
from collections.abc import Hashable, Sized

def f(x: Hashable) -> Sized: ...

``typing.TypeGuard``
====================

*Available since:* Python 3.13, typing-extensions

:data:`TypeIs <typing.TypeIs>` is an alternative to
:data:`TypeGuard <typing.TypeGuard>` that usually has more intuitive
behavior, but has other restrictions. See the documentation for
:data:`TypeIs <typing.TypeIs>` for more information.

Review existing uses of :data:`TypeGuard <typing.TypeGuard>` to see if they
should be replaced with :data:`TypeIs <typing.TypeIs>`.