Registry / type-stubs / trio-typing

trio-typing

JSON →
library0.10.0pypypi✓ verified 27d ago

trio-typing provides static type checking support for Trio and related projects. It offers PEP 561 typing stubs for `trio`, `outcome`, and `async_generator`, along with a `mypy` plugin to enhance type checking capabilities for asynchronous code. The current version is 0.10.0, and it follows the release cadence of the broader Trio ecosystem.

pip install trio-typing
INSTALL
IMPORT
SIG · TRIO-TYPING
T
trio-typing
type-stubspythonv0.10.0
Install
3.7s avg
Import
328ms
Disk
88MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.331s · 89.9MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 3.7s · import 0.325s · 88MB
88MB installed
● package 88MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TaskStatus
✓ from trio_typing import TaskStatus
Type hint for objects passed to nursery.start().
AsyncGenerator
✓ from trio_typing import AsyncGenerator
Type hint for asynchronous generators. On Python 3.6+, this re-exports typing.AsyncGenerator.
Nursery
✓ from trio import Nursery
✗ from trio_typing import Nursery
As of Trio 0.12.0, the actual Trio Nursery class is publicly exported directly from the trio package, and should be imported from there for type hinting.
plugin
✓ plugins = trio_typing.plugin # in mypy.ini
Mypy plugin for Trio-specific type checking enhancements.

This example demonstrates how to use `trio_typing.TaskStatus` for type-hinting tasks started with `trio.Nursery.start()`. It also implicitly shows how `trio.Nursery` is imported directly from `trio`. To leverage the full type-checking power, ensure you install `trio-typing[mypy]` and configure the plugin in your `mypy.ini`.

import trio from trio_typing import TaskStatus from typing import TypeVar T = TypeVar("T") async def child_task(value: T, *, task_status: TaskStatus[T]) -> None: """An asynchronous task that signals its start status.""" print(f"Child task received: {value}") task_status.started(f"Processed: {value}") # Type-checked by trio-typing await trio.sleep(0.1) async def main() -> None: """Main function demonstrating nursery.start with type hints.""" print("Starting main...") async with trio.open_nursery() as nursery: # mypy will check that 'child_task' matches the expected signature for nursery.start result = await nursery.start(child_task, "hello") print(f"Nursery start returned: {result}") print("Main finished.") if __name__ == "__main__": # To enable mypy checks, ensure you have mypy installed with trio-typing[mypy] # and 'plugins = trio_typing.plugin' in your mypy.ini file. # Example mypy.ini: # [mypy] # plugins = trio_typing.plugin # # Then run: mypy your_script_name.py trio.run(main)
Debug
Known issues
breakingVersions of trio-typing 0.10.0 and later require Mypy 1.0 or newer due to changes in Mypy's plugin API.
fix
Upgrade Mypy to version 1.0 or greater (`pip install --upgrade mypy`).
affects: 0.10.0+
deprecatedThe `Nursery` type should now be imported directly from the `trio` package (`from trio import Nursery`). Importing `Nursery` from `trio_typing` is deprecated.
fix
Change your import statement from `from trio_typing import Nursery` to `from trio import Nursery`.
affects: Since Trio 0.12.0
gotchaWhile Trio itself supports both CPython and PyPy runtimes, static type checking with `mypy` and `trio-typing` must currently occur on CPython environments, due to limitations of `mypy`.
fix
Perform static type checking in a CPython environment.
affects: All versions
gotchaWhen listing dependencies for a library that uses `trio_typing`, avoid specifying `trio-typing[mypy]` in `install_requires`. This would needlessly add a `mypy` dependency to every application transitively depending on your library. Instead, list `trio-typing` as a regular dependency and specify `mypy` (and `trio-typing[mypy]`) in development-specific dependencies (e.g., `requirements-dev.txt` or `pyproject.toml`'s `[project.optional-dependencies.dev]`).
fix
Adjust your project's dependency management to separate runtime and development/type-checking dependencies.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'trio_typing'
The `trio-typing` package is not installed in the active Python environment.
fix
pip install trio-typing
mypy: Configuration error: Plugin trio_typing.plugin could not be loaded: No module named 'trio_typing.plugin'
The `mypy` configuration specifies `trio_typing.plugin`, but the `trio-typing` package is either not installed or not accessible to `mypy`.
fix
Ensure `trio-typing` is installed (`pip install trio-typing`) and that your `mypy.ini` file's `[mypy]` section contains `plugins = trio_typing.plugin`.
error: "Event" has no attribute "wait" [attr-defined]
The `mypy` type checker cannot find type information for `trio.Event` and its methods, likely because the `trio-typing` stubs are not loaded or its `mypy` plugin is not active.
fix
Ensure `trio-typing` is installed (`pip install trio-typing`) and that your `mypy.ini` file's `[mypy]` section contains `plugins = trio_typing.plugin`.
Upgrade
Version history
0.10.0latest on PyPI · released Dec 1, 2023
Audit
Dependencies
triorequiredProvides the core asynchronous framework that trio-typing provides type hints for. Requires trio v0.11.0 or later for full stub compatibility.
mypyoptionalRequired to use the Mypy plugin for enhanced static analysis of Trio code. Installed via the `[mypy]` extra.
outcomerequiredtrio-typing provides type stubs for this package.
async_generatorrequiredtrio-typing provides type stubs for this package.
Agent activity
31 hits · last 30 days
node
28
Amazon
1
OpenAI (training)
1
Resources
trio-typing — pip install trio-typing · libregistry