@@ -335,29 +335,25 @@ Using new additions to the typing module
335
335
----------------------------------------
336
336
337
337
You 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.
340
339
341
340
The easiest way to do this is to install and use the ``typing_extensions ``
342
341
package from PyPI for the relevant imports, for example:
343
342
344
343
.. code-block :: python
345
344
346
- from typing_extensions import Literal
347
- x: Literal[" open" , " close" ]
345
+ from typing_extensions import TypeIs
348
346
349
347
If you don't want to rely on ``typing_extensions `` being installed on newer
350
348
Pythons, you could alternatively use:
351
349
352
350
.. code-block :: python
353
351
354
352
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
357
355
else :
358
- from typing_extensions import Literal
359
-
360
- x: Literal[" open" , " close" ]
356
+ from typing_extensions import TypeIs
361
357
362
358
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