From 46b05a4c10ed3841c9bc5126ba9f31dd8ae061e7 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 18 Nov 2024 13:10:13 +0100 Subject: [PATCH] Modernizing guide: Mention TypeGuard/TypeIs (#1887) --- docs/guides/modernizing.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/guides/modernizing.rst b/docs/guides/modernizing.rst index 2d17b636..a4eb3d5a 100644 --- a/docs/guides/modernizing.rst +++ b/docs/guides/modernizing.rst @@ -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 ` is an alternative to +:data:`TypeGuard ` that usually has more intuitive +behavior, but has other restrictions. See the documentation for +:data:`TypeIs ` for more information. + +Review existing uses of :data:`TypeGuard ` to see if they +should be replaced with :data:`TypeIs `.