@@ -335,29 +335,25 @@ Using new additions to the typing module
335335----------------------------------------
336336
337337You may find yourself wanting to use features added to the :py:mod: `typing `
338- module in earlier versions of Python than the addition, for example, using any
339- of ``Literal ``, ``Protocol ``, ``TypedDict `` with Python 3.6.
338+ module in earlier versions of Python than the addition.
340339
341340The easiest way to do this is to install and use the ``typing_extensions ``
342341package from PyPI for the relevant imports, for example:
343342
344343.. code-block :: python
345344
346- from typing_extensions import Literal
347- x: Literal[" open" , " close" ]
345+ from typing_extensions import TypeIs
348346
349347 If you don't want to rely on ``typing_extensions `` being installed on newer
350348Pythons, you could alternatively use:
351349
352350.. code-block :: python
353351
354352 import sys
355- if sys.version_info >= (3 , 8 ):
356- from typing import Literal
353+ if sys.version_info >= (3 , 13 ):
354+ from typing import TypeIs
357355 else :
358- from typing_extensions import Literal
359-
360- x: Literal[" open" , " close" ]
356+ from typing_extensions import TypeIs
361357
362358 This plays nicely well with following :pep: `508 ` dependency specification:
363- ``typing_extensions; python_version<"3.8 " ``
359+ ``typing_extensions; python_version<"3.13 " ``
0 commit comments