README.rst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. =================
  2. Typing Extensions
  3. =================
  4. .. image:: https://badges.gitter.im/python/typing.svg
  5. :alt: Chat at https://gitter.im/python/typing
  6. :target: https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
  7. Overview
  8. ========
  9. The ``typing`` module was added to the standard library in Python 3.5 on
  10. a provisional basis and will no longer be provisional in Python 3.7. However,
  11. this means users of Python 3.5 - 3.6 who are unable to upgrade will not be
  12. able to take advantage of new types added to the ``typing`` module, such as
  13. ``typing.Text`` or ``typing.Coroutine``.
  14. The ``typing_extensions`` module contains both backports of these changes
  15. as well as experimental types that will eventually be added to the ``typing``
  16. module, such as ``Protocol`` (see PEP 544 for details about protocols and
  17. static duck typing) or ``TypedDict`` (see PEP 589).
  18. Users of other Python versions should continue to install and use
  19. the ``typing`` module from PyPi instead of using this one unless
  20. specifically writing code that must be compatible with multiple Python
  21. versions or requires experimental types.
  22. Included items
  23. ==============
  24. This module currently contains the following:
  25. All Python versions:
  26. --------------------
  27. - ``ClassVar``
  28. - ``ContextManager``
  29. - ``Counter``
  30. - ``DefaultDict``
  31. - ``Deque``
  32. - ``final``
  33. - ``Final``
  34. - ``Literal``
  35. - ``NewType``
  36. - ``NoReturn``
  37. - ``overload`` (note that older versions of ``typing`` only let you use ``overload`` in stubs)
  38. - ``OrderedDict``
  39. - ``Protocol`` (except on Python 3.5.0)
  40. - ``runtime_checkable`` (except on Python 3.5.0)
  41. - ``Text``
  42. - ``Type``
  43. - ``TypedDict``
  44. - ``TypeAlias``
  45. - ``TYPE_CHECKING``
  46. Python 3.4+ only:
  47. -----------------
  48. - ``ChainMap``
  49. - ``ParamSpec``
  50. - ``Concatenate``
  51. - ``ParamSpecArgs``
  52. - ``ParamSpecKwargs``
  53. - ``TypeGuard``
  54. Python 3.5+ only:
  55. -----------------
  56. - ``Annotated`` (except on Python 3.5.0-3.5.2)
  57. - ``AsyncIterable``
  58. - ``AsyncIterator``
  59. - ``AsyncContextManager``
  60. - ``Awaitable``
  61. - ``Coroutine``
  62. Python 3.6+ only:
  63. -----------------
  64. - ``AsyncGenerator``
  65. Other Notes and Limitations
  66. ===========================
  67. There are a few types whose interface was modified between different
  68. versions of typing. For example, ``typing.Sequence`` was modified to
  69. subclass ``typing.Reversible`` as of Python 3.5.3.
  70. These changes are _not_ backported to prevent subtle compatibility
  71. issues when mixing the differing implementations of modified classes.
  72. Certain types have incorrect runtime behavior due to limitations of older
  73. versions of the typing module. For example, ``ParamSpec`` and ``Concatenate``
  74. will not work with ``get_args``, ``get_origin``. Certain PEP 612 special cases
  75. in user-defined ``Generic``\ s are also not available.
  76. These types are only guaranteed to work for static type checking.
  77. Running tests
  78. =============
  79. To run tests, navigate into the appropriate source directory and run
  80. ``test_typing_extensions.py``. You will also need to install the latest
  81. version of ``typing`` if you are using a version of Python that does not
  82. include ``typing`` as a part of the standard library.