{"id":28537565,"url":"https://github.com/python-trio/trio-typing","last_synced_at":"2025-07-08T07:31:28.541Z","repository":{"id":36475478,"uuid":"159905905","full_name":"python-trio/trio-typing","owner":"python-trio","description":"Type hints for Trio and related projects","archived":false,"fork":false,"pushed_at":"2024-10-24T14:54:36.000Z","size":210,"stargazers_count":29,"open_issues_count":8,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-28T09:32:38.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-trio.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"python-trio","open_collective":"python-trio"}},"created_at":"2018-12-01T03:40:41.000Z","updated_at":"2025-06-19T15:34:14.000Z","dependencies_parsed_at":"2023-11-21T19:05:01.109Z","dependency_job_id":"f0586638-6721-4bb4-914d-d9415c738eca","html_url":"https://github.com/python-trio/trio-typing","commit_stats":{"total_commits":128,"total_committers":17,"mean_commits":7.529411764705882,"dds":0.25,"last_synced_commit":"4d7cb8ca3b319169c95aea439cfc66bea5855af2"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/python-trio/trio-typing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-typing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-typing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-typing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-typing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-trio","download_url":"https://codeload.github.com/python-trio/trio-typing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-typing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262597735,"owners_count":23334641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T18:10:14.192Z","updated_at":"2025-07-08T07:31:28.534Z","avatar_url":"https://github.com/python-trio.png","language":"Python","funding_links":["https://github.com/sponsors/python-trio","https://opencollective.com/python-trio"],"categories":[],"sub_categories":[],"readme":".. image:: https://img.shields.io/pypi/v/trio-typing.svg\n   :target: https://pypi.org/project/trio-typing\n   :alt: Latest PyPI version\n\n.. image:: https://travis-ci.org/python-trio/trio-typing.svg?branch=master\n   :target: https://travis-ci.org/python-trio/trio-typing\n   :alt: Automated test status\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/ambv/black\n   :alt: Code style: black\n\n.. image:: http://www.mypy-lang.org/static/mypy_badge.svg\n   :target: http://www.mypy-lang.org/\n   :alt: Checked with mypy\n\ntrio-typing: static typing for Trio and related projects\n========================================================\n\nThis repository provides:\n\n* PEP 561 typing stubs packages for the Trio project packages:\n\n  * `trio \u003chttps://github.com/python-trio/trio\u003e`__ (``trio-stubs``)\n\n  * `outcome \u003chttps://github.com/python-trio/outcome\u003e`__ (``outcome-stubs``)\n\n  * `async_generator \u003chttps://github.com/python-trio/async_generator\u003e`__\n    (``async_generator-stubs``)\n\n* A package ``trio_typing`` containing types that Trio programs often want\n  to refer to (``AsyncGenerator[Y, S]`` and ``TaskStatus[T]``)\n  (``Nursery`` is exported publicly by mainline Trio as of version 0.12.0.)\n\n* A mypy plugin that smooths over some limitations in the basic type hints.\n\n\nSupported platforms\n~~~~~~~~~~~~~~~~~~~\n\nLike Trio, we require Python 3.7 or later. Both PyPy and CPython are\nsupported at runtime, but type checking must occur on CPython (due to\nlimitations of mypy).  We test on Linux using the latest releases\nfrom the 3.7, 3.8, 3.9, and 3.10 branches. We're\nnot knowingly doing anything OS-specific, so other OSes should work\ntoo.\n\nType checkers other than mypy are not supported, but might work.\nExperience reports and patches to add support are welcome.\n\n\nQuickstart\n~~~~~~~~~~\n\nruntime only\n------------\n\nInstall with::\n\n    pip install trio-typing\n\nThen import some typing names from ``trio_typing``, like ``TaskStatus``;\nsee below for more details.\n\n\nwith mypy support\n-----------------\n\nInstall trio-typing with mypy extras::\n\n    pip install trio-typing[mypy]\n\nNote that due to recent plugin API changes, trio-typing 0.10.0+ requires mypy 1.0+.\n\nEnable the plugin in your ``mypy.ini``::\n\n    [mypy]\n    plugins = trio_typing.plugin\n\nStart running mypy on your Trio code!\n\nNOTE: ``trio-typing`` is the correct dependency to list in the requirements\n  of your own library using the ``trio_typing`` module.  Don't use\n  ``trio-typing[mypy]``, since that would needlessly add a mypy dependency to\n  every app having a transitive dependency on your library.\n\n\nWhat's in the box?\n~~~~~~~~~~~~~~~~~~\n\nThe stubs packages provide types for all public non-deprecated APIs of\n``trio``, ``outcome``, and ``async_generator``, as of the release date\nof the corresponding ``trio-typing`` distribution. You don't need to\nexplicitly configure these; just say ``import trio`` (for example)\nand mypy will know to look in ``trio-stubs`` for the type information.\n\nThe ``trio_typing`` package provides:\n\n* ``TaskStatus[T]``, the type of the object passed as the ``task_status``\n  argument to a task started with ``nursery.start()``. The type parameter\n  ``T`` is the type of the value the task provides to be returned from\n  ``nursery.start()``. This is implemented as an ABC, and the actual\n  private types inside Trio are registered as virtual subclasses\n  of it. So, you can't instantiate ``trio_typing.TaskStatus``, but\n  ``isinstance(task_status, trio_typing.TaskStatus)`` where ``task_status``\n  is a Trio task status object does return True.\n\n* (Previous versions of ``trio_typing`` provided an analogous ABC for\n  ``Nursery``, but the actual class is available as ``trio.Nursery`` as of\n  Trio 0.12.0; you should use that instead.)\n\n* A backport of ``typing.AsyncGenerator[YieldT, SendT]`` to Python 3.5.\n  (``YieldT`` is the type of values yielded by the generator, and\n  ``SendT`` is the type of values it accepts as an argument to ``asend()``.)\n  This is an abstract class describing the async generator interface:\n  ``AsyncIterator`` plus ``asend``, ``athrow``, ``aclose``, and the\n  ``ag_*`` introspection attributes. On 3.6+, ``trio_typing.AsyncGenerator``\n  is just a reexport of ``typing.AsyncGenerator``.\n\n* ``CompatAsyncGenerator[YieldT, SendT, ReturnT]``,\n  a name for the otherwise-anonymous concrete async generator type\n  returned by ``@async_generator`` functions. It is a subtype of\n  ``AsyncGenerator[YieldT, SendT]`` and provides the same methods.\n  (Native async generators don't have a ``ReturnT``; it is only relevant\n  in determining the return type of ``await async_generator.yield_from_()``.)\n\n* A few types that are only useful with the mypy plugin: ``YieldType[T]``,\n  ``SendType[T]``, and the decorator ``@takes_callable_and_args``.\n\nThe ``trio_typing.plugin`` mypy plugin provides:\n\n* Inference of more specific ``trio.open_file()`` and ``trio.Path.open()``\n  return types based on constant ``mode`` and ``buffering`` arguments, so\n  ``await trio.open_file(\"foo\", \"rb\", 0)`` returns an unbuffered async\n  file object in binary mode and ``await trio.open_file(\"bar\")`` returns\n  an async file object in text mode\n\n* Boilerplate reduction for functions that take parameters ``(fn, *args)``\n  and ultimately invoke ``fn(*args)``: just write::\n\n      from mypy_extensions import VarArg\n\n      @trio_typing.takes_callable_and_args\n      def start_soon(\n          async_fn: Callable[[VarArg()], Awaitable[T]],\n          *args: Any,\n          other_keywords: str = are_ok_too,\n      ):\n          # your implementation here\n\n  ``start_soon(async_fn, *args)`` will raise an error if ``async_fn(*args)``\n  would do so. You can also make the callable take some non-splatted\n  arguments; the ``*args`` get inserted at whatever position in the\n  argument list you write ``VarArg()``.\n\n  The above example will always fail when the plugin is not being\n  used. If you want to always pass in such cases, you can use a union::\n\n      @trio_typing.takes_callable_and_args\n      def start_soon(\n          async_fn: Union[\n              Callable[..., Awaitable[T]],\n              Callable[[VarArg()], Awaitable[T]],\n          ],\n          *args: Any,\n          other_keywords: str = are_ok_too,\n      ):\n          # your implementation here\n\n  Without the plugin, this type-checks fine (and allows inference of\n  ``T``), since any callable will match the ``Callable[...,\n  Awaitable[T]]`` option. With the plugin, the entire union will be\n  replaced with specific argument types.\n\n  Note: due to mypy limitations, we only support a maximum of 5\n  positional arguments, and keyword arguments can't be passed in this way;\n  ``nursery.start_soon(functools.partial(...))`` will pass the type checker\n  but won't be able to actually check the argument types.\n\n* Mostly-full support for type checking ``@async_generator`` functions.\n  You write the decorated function as if it returned a union of its actual\n  return type, its yield type wrapped in ``YieldType[]``, and its send\n  type wrapped in ``SendType[]``::\n\n      from trio_typing import YieldType, SendType\n      @async_generator\n      async def sleep_and_sqrt() -\u003e Union[None, SendType[int], YieldType[float]]:\n          next_yield = 0.0\n          while True:\n              amount = await yield_(next_yield)  # amount is an int\n              if amount \u003c 0:\n                  return None\n              await trio.sleep(amount)\n              next_yield = math.sqrt(amount)\n\n      # prints: CompatAsyncGenerator[float, int, None]\n      reveal_type(sleep_and_sqrt())\n\n  Calls to ``yield_`` and ``yield_from_`` inside an ``@async_generator``\n  function are type-checked based on these declarations. If you leave\n  off *either* the yield type or send type, the missing one is assumed\n  to be ``None``; if you leave off *both* (writing just\n  ``async def sleep_and_sqrt() -\u003e None:``, like you would if you weren't\n  using the plugin), they're both assumed to be ``Any``.\n\n  Note the explicit ``return None``; mypy won't accept ``return`` or\n  falling off the end of the function, unless you run it with\n  ``--no-warn-no-return``.\n\n\nLimitations\n~~~~~~~~~~~\n\n* Calls to variadic Trio functions like ``trio.run()``,\n  ``nursery.start_soon()``, and so on, only can type-check up to five\n  positional arguments. (This number could be increased easily, but\n  only at the cost of slower typechecking for everyone; mypy's current\n  architecture requires that we generate overload sets initially for\n  every arity we want to be able to use.) You can work around this with\n  a ``# type: ignore`` comment.\n\n* ``outcome.capture()`` and ``outcome.acapture()`` currently don't typecheck\n  their arguments at all.\n\n\nRunning the tests\n~~~~~~~~~~~~~~~~~\n\n``trio-typing`` comes with a fairly extensive testsuite; it doesn't test all\nthe mechanical parts of the stubs, but does exercise most of the interesting\nplugin behavior. You can run it after installing, with::\n\n    pytest -p trio_typing._tests.datadriven --pyargs trio_typing\n\n\nLicense\n~~~~~~~\n\nYour choice of MIT or Apache 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Ftrio-typing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-trio%2Ftrio-typing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Ftrio-typing/lists"}