[Twisted-Python] Running tests with monkeytype
![](https://secure.gravatar.com/avatar/f1b9eda8229c1ce71bcef8d6fd5eb804.jpg?s=120&d=mm&r=g)
Hi all, If you want to get a first rough draft of types for mypy, has anyone tried running the tests under monkeytype[1]? Moshe Z. [1] https://monkeytype.readthedocs.io/en/stable/
![](https://secure.gravatar.com/avatar/fbd473e7e3b6675a84cd3c3b4a2c1972.jpg?s=120&d=mm&r=g)
On Saturday, 20 June 2020 06:51:21 CEST Moshe Zadka wrote:
That would be worth running in any case, if only as a reference. Whether it would be worth applying as-is, I'm not sure: monkeytype would capture the concrete type passed to functions, while in the type annotations we'd want to have Zope interfaces and abstract types (Iterable etc) instead. With some scripted filtering, maybe we can apply part of monkeytype's captured types automatically. We don't need to automate 100%; any substantial amount will save a lot of manual work. Another thing we could do to automate annotation is extract the documented types from the docstrings. For example by modifying pydoctor. Which also brings up the question: in the long term (*), do we want to have both type annotations and types in the docstring? Or do we only want to document types in docstrings if there is no exact annotations possible in Python's type system? (*) Currently, pydoctor uses Python 3.6 style ("var: type") annotations for variables, but it ignores annotations for functions and it ignores type comments. Function annotations are on my to-do list, while type comments are supported by Python 3.8's ast module. So eventually, all annotations should end up in the output of pydoctor. Bye, Maarten
![](https://secure.gravatar.com/avatar/bcb6ef473ff1644fddee1b4e7c730b01.jpg?s=120&d=mm&r=g)
On Sat, Jun 20, 2020, at 3:10 PM, Maarten ter Huurne wrote:
Let's definitely move to type annotations, since they are much more likely to be correct due to validation by MyPy. To start, we'll need to revise the Twisted coding standard [1] to permit type annotations instead of @type lines in the docstring. I think that we should suggest, but not require, annotation syntax to start. I filed a ticket [2] for this. ---Tom [1]: https://twistedmatrix.com/documents/current/core/development/policy/coding-s... [2]: https://twistedmatrix.com/trac/ticket/9859
![](https://secure.gravatar.com/avatar/469df05f5dfd5b75fb3cb3a0868d36bf.jpg?s=120&d=mm&r=g)
On Sat, Jun 20, 2020 at 4:02 PM Tom Most <twm@freecog.net> wrote:
Revising the Twisted coding standard to permit (and even encourage) type annotations is a great idea. Using epydoc's @type tags in docstring was OK, but epydoc is not a tool that is universally used in the Python world. At the time, using epydoc tags was the best that could be done. Type annotations are a first-level language feature, that is part of the core Python toolchain. There seems to be growing support for type annotations from various tools, IDE's, Python libraries, and the core Python toolchain itself. -- Craig
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
I'm 100% in favor of moving to type annotations exclusively and getting rid of @type from everywhere. In fact this has been the plan since 2017: https://github.com/twisted/pydoctor/issues/136 <https://github.com/twisted/pydoctor/issues/136> Getting that issue resolved is the only blocker at this point :) -g
![](https://secure.gravatar.com/avatar/fbd473e7e3b6675a84cd3c3b4a2c1972.jpg?s=120&d=mm&r=g)
On Saturday, 20 June 2020 06:51:21 CEST Moshe Zadka wrote:
That would be worth running in any case, if only as a reference. Whether it would be worth applying as-is, I'm not sure: monkeytype would capture the concrete type passed to functions, while in the type annotations we'd want to have Zope interfaces and abstract types (Iterable etc) instead. With some scripted filtering, maybe we can apply part of monkeytype's captured types automatically. We don't need to automate 100%; any substantial amount will save a lot of manual work. Another thing we could do to automate annotation is extract the documented types from the docstrings. For example by modifying pydoctor. Which also brings up the question: in the long term (*), do we want to have both type annotations and types in the docstring? Or do we only want to document types in docstrings if there is no exact annotations possible in Python's type system? (*) Currently, pydoctor uses Python 3.6 style ("var: type") annotations for variables, but it ignores annotations for functions and it ignores type comments. Function annotations are on my to-do list, while type comments are supported by Python 3.8's ast module. So eventually, all annotations should end up in the output of pydoctor. Bye, Maarten
![](https://secure.gravatar.com/avatar/bcb6ef473ff1644fddee1b4e7c730b01.jpg?s=120&d=mm&r=g)
On Sat, Jun 20, 2020, at 3:10 PM, Maarten ter Huurne wrote:
Let's definitely move to type annotations, since they are much more likely to be correct due to validation by MyPy. To start, we'll need to revise the Twisted coding standard [1] to permit type annotations instead of @type lines in the docstring. I think that we should suggest, but not require, annotation syntax to start. I filed a ticket [2] for this. ---Tom [1]: https://twistedmatrix.com/documents/current/core/development/policy/coding-s... [2]: https://twistedmatrix.com/trac/ticket/9859
![](https://secure.gravatar.com/avatar/469df05f5dfd5b75fb3cb3a0868d36bf.jpg?s=120&d=mm&r=g)
On Sat, Jun 20, 2020 at 4:02 PM Tom Most <twm@freecog.net> wrote:
Revising the Twisted coding standard to permit (and even encourage) type annotations is a great idea. Using epydoc's @type tags in docstring was OK, but epydoc is not a tool that is universally used in the Python world. At the time, using epydoc tags was the best that could be done. Type annotations are a first-level language feature, that is part of the core Python toolchain. There seems to be growing support for type annotations from various tools, IDE's, Python libraries, and the core Python toolchain itself. -- Craig
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
I'm 100% in favor of moving to type annotations exclusively and getting rid of @type from everywhere. In fact this has been the plan since 2017: https://github.com/twisted/pydoctor/issues/136 <https://github.com/twisted/pydoctor/issues/136> Getting that issue resolved is the only blocker at this point :) -g
participants (5)
-
Craig Rodrigues
-
Glyph
-
Maarten ter Huurne
-
Moshe Zadka
-
Tom Most