[Twisted-Python] Running tests with monkeytype

2020-06-19 Thread Moshe Zadka
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/___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Running tests with monkeytype

2020-06-20 Thread Maarten ter Huurne
On Saturday, 20 June 2020 06:51:21 CEST Moshe Zadka wrote:
> 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/

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



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Running tests with monkeytype

2020-06-20 Thread Tom Most
On Sat, Jun 20, 2020, at 3:10 PM, Maarten ter Huurne wrote:
> 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?

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-standard.html#docstrings
[2]: https://twistedmatrix.com/trac/ticket/9859

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Running tests with monkeytype

2020-06-21 Thread Craig Rodrigues
On Sat, Jun 20, 2020 at 4:02 PM Tom Most  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.
>
>
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
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Running tests with monkeytype

2020-06-22 Thread Glyph


> On Jun 21, 2020, at 10:18 PM, Craig Rodrigues  wrote:
> 
> 
> 
> On Sat, Jun 20, 2020 at 4:02 PM Tom Most  > 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.
> 
> 
> 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.

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 


Getting that issue resolved is the only blocker at this point :)

-g

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python