# Trio-typing: new package of static type hints for Trio and friends

**URL:** <https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70>\
**Category:** Announcements\
**Created:** [February 11, 2019, 1:01am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70 "2019-02-11T01:01:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oremanj](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/oremanj/32/106_2.png) [@oremanj](https://trio.discourse.group/u/oremanj)\
**Post date:** [February 11, 2019, 1:01am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70/1 "2019-02-11T01:01:56Z")

</div>

I’ve been writing Trio-using code using static type annotations (PEP 484 / mypy / etc) for a few months, and have finally gotten around to packaging the Trio stubs I wrote with a mypy plugin that smooths over some pitfalls. You can get it on PyPI: `pip install trio-typing`. It comes with stubs for `trio`, `outcome`, and `async_generator`, a package `trio_typing` from which you can import type names like `Nursery` and `TaskStatus`, and a mypy plugin `trio_typing.plugin`. See [https://github.com/python-trio/trio-typing/blob/master/README.rst](https://github.com/python-trio/trio-typing/blob/master/README.rst) for more details.

In the long run I suspect we’d like to have these integrated into Trio, but Trio is a little too dynamic for that to be an easy task at the moment, and I wanted to let other folks start building statically-typed Trio applications in the meantime. Feedback and experience reports would be much appreciated!

You’ll need trio v0.11.0 (released yesterday) or later, to support writing `trio.CancelScope` and `trio.abc.SendChannel[SomeObjectType]`.

---

<div class="post-metadata">

**Author:** ![njs](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/njs/32/11_2.png) [@njs](https://trio.discourse.group/u/njs)\
**Post date:** [February 11, 2019, 2:16am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70/2 "2019-02-11T02:16:16Z")

</div>

Wow, that’s really impressive, especially the plugin.

I was surprised to learn that mypy doesn’t understand `functools.partial`… it looks like they [they’d be happy to add a plugin](https://github.com/python/mypy/issues/1484) if someone submitted one.

Do you want to move this into the `python-trio` org?

---

<div class="post-metadata">

**Author:** ![oremanj](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/oremanj/32/106_2.png) [@oremanj](https://trio.discourse.group/u/oremanj)\
**Post date:** [February 11, 2019, 2:28am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70/3 "2019-02-11T02:28:46Z")

</div>

I started working on a plugin to support `partial` but ran into too many issues for the time I had available. I do hope to add that support eventually!

I’d be happy to move this into `python-trio` if there’s someone else who’s willing to review changes to the mypy plugin that might be needed or wanted in the future. I wasn’t sure if such a person existed, and I didn’t want to sign anyone up for the “self-taught familiarization with mypy internals” crash course without their consent. 🙂

---

<div class="post-metadata">

**Author:** ![njs](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/njs/32/11_2.png) [@njs](https://trio.discourse.group/u/njs)\
**Post date:** [February 11, 2019, 2:43am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70/4 "2019-02-11T02:43:39Z")

</div>

> [@oremanj](#):
>
> I’d be happy to move this into `python-trio` if there’s someone else who’s willing to review changes to the mypy plugin that might be needed or wanted in the future.

Eh, I wouldn’t worry about it. It’s surprising how much better even perfunctory review is compared to no review 🙂 And if there’s really no-one willing to review, then we can always change the rules; the rules are supposed to help us, not hamstring us.

---

<div class="post-metadata">

**Author:** ![oremanj](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/oremanj/32/106_2.png) [@oremanj](https://trio.discourse.group/u/oremanj)\
**Post date:** [February 11, 2019, 2:45am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70/5 "2019-02-11T02:45:52Z")

</div>

Sounds good - I’ve moved it over!

---

<div class="post-metadata">

**Author:** ![oremanj](https://yyz2.discourse-cdn.com/free1/user_avatar/trio.discourse.group/oremanj/32/106_2.png) [@oremanj](https://trio.discourse.group/u/oremanj)\
**Post date:** [October 17, 2019, 4:00am UTC](https://trio.discourse.group/t/trio-typing-new-package-of-static-type-hints-for-trio-and-friends/70/6 "2019-10-17T04:00:43Z")

</div>

trio-typing v0.3.0 has been released to PyPI with support for APIs added in Trio 0.12.0. It also contains some updates to support new versions of mypy; it now targets mypy 0.740, released today.
