# Type Annotations + mypyc compiling ansible

**URL:** <https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671>\
**Category:** Ansible Project\
**Created:** [May 30, 2022, 8:30pm UTC](https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671 "2022-05-30T20:30:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cooper\_Lees](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Cooper\_Lees](https://forum.ansible.com/u/Cooper_Lees)\
**Post date:** [May 30, 2022, 8:30pm UTC](https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671/1 "2022-05-30T20:30:11Z")

</div>

Hi All,

I saw [https://github.com/ansible/ansible/issues/69424](https://github.com/ansible/ansible/issues/69424) indicated that type annotations was not considered for the ansible code base. I would like to revist this topic and share the added on ability to potentially “compile” ansible using mypyc to get performance and resource usage wins for anisble itself.

I personally run ansible-playbook over my personal infra of 6 VPS’s and home routers and am very surprised at the resources it uses to do so.

Here is some good points on why this could be a good thing to support:

- [https://glyph.twistedmatrix.com/2022/04/you-should-compile-your-python-and-heres-why.html](https://glyph.twistedmatrix.com/2022/04/you-should-compile-your-python-and-heres-why.html)
- We also converted black (as I am a maintainer) to mypyc and saw a ~2x speedup

I understand this is a large undertaking, but was just wanting to see peoples point of views here. Thoughts?

---

<div class="post-metadata">

**Author:** ![Michael5](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Michael5](https://forum.ansible.com/u/Michael5)\
**Post date:** [June 5, 2022, 6:21pm UTC](https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671/2 "2022-06-05T18:21:11Z")

</div>

Hi, I’ve started adding type stubs for the Ansible codebase, currently its not public

понедельник, 30 мая 2022 г. в 23:30:11 UTC+3, Cooper Lees:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 6, 2022, 4:55pm UTC](https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671/3 "2022-06-06T16:55:51Z")

</div>

We are working towards type annotations. I would recommend reading over the proposal[1] that we have largely agreed to. But regardless, this isn’t something that will happen overnight, it will likely take years. And we don’t have any intention of just blanket applying it to the whole code base up front. It’ll be slow, and only added as necessary. In some cases, it may require rewriting code, which in some cases could also require deprecation cycles.

[1] [https://github.com/ansible/proposals/issues/202](https://github.com/ansible/proposals/issues/202)

---

<div class="post-metadata">

**Author:** ![Michael5](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Michael5](https://forum.ansible.com/u/Michael5)\
**Post date:** [June 6, 2022, 6:01pm UTC](https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671/4 "2022-06-06T18:01:37Z")

</div>

It can be firstly added to typeshed.

пн, 6 июн. 2022 г., 19:56 Matt Martz \<[matt@sivel.net](mailto:matt@sivel.net)\>:

---

<div class="post-metadata">

**Author:** ![Cooper\_Lees](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Cooper\_Lees](https://forum.ansible.com/u/Cooper_Lees)\
**Post date:** [June 6, 2022, 6:04pm UTC](https://forum.ansible.com/t/type-annotations-mypyc-compiling-ansible/36671/5 "2022-06-06T18:04:13Z")

</div>

Awesome news to hear this is happening. I do appreciate the time required here and the need for refactoring to make Python code more type sane.

Cheers,  
Cooper
