Hi Dan,

On Sat, Jul 30, 2022 at 12:54 PM Dan Stromberg <strom...@gmail.com> wrote:

>
> Thanks for the reply.
>
> I was actually wondering....  Black does a before-and-after AST comparison
> for reliability.  Does MonkeyType do anything like that?
>

No. This wouldn’t make sense for MonkeyType, since type annotations are
part of the AST, so MonkeyType’s entire purpose is to modify the AST. If it
does anything at all, it would always “fail” such a test. Unlike Black,
which should modify only syntactic trivia that is invisible in the AST.

And if not, would MonkeyType be less prone to introducing bugs if we run
> Black first?
>

Not unless there’s a bug in LibCST (the underlying codemod library used by
MonkeyType) where it chokes on some super strange code formatting. But this
is unlikely.

The kinds of bugs MonkeyType is likely to introduce are not code formatting
related, but logical bugs related to the type annotations it adds; eg
MonkeyType can easily create circular imports in your code, if you don’t
use `from __future__ import annotations`. You definitely want to run your
test suite and your type checker after running MonkeyType, and review/edit
the changes manually as needed. MonkeyType changes are definitely not
intended to commit blindly.

You probably also want to run Black _after_ MonkeyType, since MonkeyType
may modify your code in such a way that it no longer conforms to Black
formatting.

Carl (MonkeyType maintainer)
_______________________________________________
code-quality mailing list -- code-quality@python.org
To unsubscribe send an email to code-quality-le...@python.org
https://mail.python.org/mailman3/lists/code-quality.python.org/
Member address: arch...@mail-archive.com

Reply via email to