From: John Snow <jsnow@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
qemu-devel@nongnu.org, "Eduardo Habkost" <ehabkost@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>
Subject: Re: [PATCH 16/37] qapi: establish mypy type-checking baseline
Date: Mon, 21 Sep 2020 10:41:27 -0400 [thread overview]
Message-ID: <510ead18-a91c-8d25-880a-99a9d628a25e@redhat.com> (raw)
In-Reply-To: <87k0wna723.fsf@dusky.pond.sub.org>
On 9/21/20 4:05 AM, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
>
>> On 9/18/20 7:55 AM, Markus Armbruster wrote:
>>> Ignorant question: why does this come after PATCH 13 "qapi/common.py:
>>> add notational type hints", but before all the other patches adding type
>>> hints?
>>> John Snow <jsnow@redhat.com> writes:
>>>
>>>> Fix two very minor issues, and then establish a mypy type-checking
>>>> baseline.
>>>>
>>>> Like pylint, this should be run from the folder above:
>>>>
>>>> > mypy --config-file=qapi/mypy.ini qapi/
>>> I get:
>>> $ mypy --config-file qapi/mypy.ini qapi
>>> qapi/mypy.ini: [mypy]: Strict mode is not supported in configuration files: specify individual flags instead (see 'mypy -h' for the list of flags enabled in strict mode)
>>> qapi/types.py:29: error: Need type annotation for 'objects_seen' (hint: "objects_seen: Set[<type>] = ...")
>>> Found 1 error in 1 file (checked 18 source files)
>>> Is this expected?
>>>
>>
>> Nope.
>>
>>> In case it matters:
>>> $ mypy --version
>>> mypy 0.761
>>>
>>
>> I am using mypy 0.782.
>>
>> I will investigate to see if there is an *easy* win to allow older
>> versions to work.
>>
>> In the meantime, please consider trying this:
>>
>> pip install --user mypy==0.782
>> ~/.local/bin/mypy --config-file=qapi/mypy.ini qapi/
>
> I'll consider dragging my feet until upgrading Fedora gives it to me for
> free.
>
> The less I interact with package managers, the happier I am.
>
I'll probably be working on making sure CI runs in a virtual environment
with specifically pinned versions.
We don't need mypy to run or build, so I have been less worried about
requiring bleeding edge versions for development and regression testing.
>>>> Signed-off-by: John Snow <jsnow@redhat.com>
>>>> ---
>>>> scripts/qapi/doc.py | 3 +-
>>>> scripts/qapi/mypy.ini | 65 ++++++++++++++++++++++++++++++++++++++++++
>>>> scripts/qapi/schema.py | 3 +-
>>>> 3 files changed, 69 insertions(+), 2 deletions(-)
>>>> create mode 100644 scripts/qapi/mypy.ini
>>>>
>>>> diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
>>>> index cbf7076ed9..70f7cdfaa6 100644
>>>> --- a/scripts/qapi/doc.py
>>>> +++ b/scripts/qapi/doc.py
>>>> @@ -5,7 +5,8 @@
>>>> """This script produces the documentation of a qapi schema in texinfo format"""
>>>> import re
>>>> -from .gen import QAPIGenDoc, QAPISchemaVisitor
>>>> +from .gen import QAPIGenDoc
>>>> +from .schema import QAPISchemaVisitor
>>> Your mypy doesn't like such lazy imports? Mine seems not to care.
>>>
>>
>> Yeah, it specifically complained that no such definition existed in
>> that file.
>
> I sense a certain wobbliness in mypy. Perhaps to be expected from a
> tool with major version zero. There's a risk that developers' local
> "make check" and our gating CI differ too much. We'll see.
>
It is indeed very cutting edge. It wasn't really viable to use until
Python 3.6.
>>>>
>>>> MSG_FMT = """
>>>> diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini
>>>> new file mode 100644
>>>> index 0000000000..a0f2365a53
>>>> --- /dev/null
>>>> +++ b/scripts/qapi/mypy.ini
>>>> @@ -0,0 +1,65 @@
>>>> +[mypy]
>>>> +strict = True
>>>> +strict_optional = False
>>>> +disallow_untyped_calls = False
>>>> +python_version = 3.6
>>>> +
>>>> +[mypy-qapi.commands]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.doc]
>>>> +disallow_subclassing_any = False
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +
>>>> +[mypy-qapi.error]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.events]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.expr]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.gen]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.introspect]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.parser]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.schema]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.source]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.types]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>>> +
>>>> +[mypy-qapi.visit]
>>>> +disallow_untyped_defs = False
>>>> +disallow_incomplete_defs = False
>>>> +check_untyped_defs = False
>>> Greek to me. I'll learn in due time.
>>>
>>
>> I am using these options:
>>
>> --strict, which is effectively -Wall.
>>
>> --no-strict-optional, which disables type checking errors on conflict
>> between Optional[T] and T. Namely, when you initialize a class field
>> to None and set that variable after initialization, callers must be
>> prepared to see if that field was None or not. We do that effectively
>> nowhere.
>>
>> As Python will surely explode in a noticeable way if we got an
>> unexpected 'None', I am just suppressing these warnings "for now".
>
> Okay.
>
> We may want to rethink how we define and initialize these variables. We
> initialize mostly to keep pylint happy. We initialize to None precisely
> to make use before the real initialization explode.
>
The pattern we have is roughly correct; it's just that we rely on that
implicit explosion, which mypy will warn about if I don't disable this
option.
It's not worth addressing in our first pass, but if you look at
schema.py's @property ifcond code, that's the type of thing that would
"fix" this warning -- basically access shims that add a "real" error
message when it's None, but convert the return type from Optional[T] to T.
It's later stuff.
>> --allow-untyped-calls silences errors in files that have calls to
>> functions in files I still have not typed. By the end of the series,
>> this option goes away, because there's nothing untyped left.
>>
>>
>> For each untyped file, we are actually starting with all of the above
>> options and then layering these options on top. Any egregious typing
>> errors present in these "ignored" files will be spotted.
>>
>> To get the bad files to pass, we only need three options:
>>
>> allow untyped defs -- Simply permits us to have functions without
>> annotations.
>>
>> allow incomplete defs -- allows functions that are only partially typed.
>>
>> check untyped defs = False -- Don't try to type check untyped definitions.
>
> Thanks!
>
> [...]
>
next prev parent reply other threads:[~2020-09-21 14:46 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-15 22:39 [PATCH 00/37] qapi: static typing conversion, pt1 John Snow
2020-09-15 22:39 ` [PATCH 01/37] python: Require 3.6+ John Snow
2020-09-16 8:42 ` Markus Armbruster
2020-09-16 8:51 ` Daniel P. Berrangé
2020-09-15 22:39 ` [PATCH 02/37] [DO-NOT-MERGE] qapi: add debugging tools John Snow
2020-09-15 22:39 ` [PATCH 03/37] qapi-gen: Separate arg-parsing from generation John Snow
2020-09-15 22:39 ` [PATCH 04/37] qapi: move generator entrypoint into module John Snow
2020-09-16 11:54 ` Markus Armbruster
2020-09-16 14:24 ` John Snow
2020-09-17 7:46 ` Markus Armbruster
2020-09-15 22:39 ` [PATCH 05/37] qapi: Remove wildcard includes John Snow
2020-09-15 22:39 ` [PATCH 06/37] qapi: delint using flake8 John Snow
2020-09-16 12:12 ` Markus Armbruster
2020-09-16 14:29 ` John Snow
2020-09-17 7:54 ` Markus Armbruster
2020-09-17 16:57 ` John Snow
2020-09-18 10:33 ` Markus Armbruster
2020-09-18 18:13 ` John Snow
2020-09-21 7:31 ` Markus Armbruster
2020-09-21 14:50 ` John Snow
2020-09-15 22:39 ` [PATCH 07/37] qapi: add pylintrc John Snow
2020-09-16 12:30 ` Markus Armbruster
2020-09-16 14:37 ` John Snow
2020-09-17 7:58 ` Markus Armbruster
2020-09-17 17:06 ` John Snow
2020-09-15 22:39 ` [PATCH 08/37] qapi/common.py: Remove python compatibility workaround John Snow
2020-09-16 12:34 ` Markus Armbruster
2020-09-16 14:38 ` John Snow
2020-09-15 22:39 ` [PATCH 09/37] qapi/common.py: Add indent manager John Snow
2020-09-16 15:13 ` Markus Armbruster
2020-09-16 22:25 ` John Snow
2020-09-17 8:07 ` Markus Armbruster
2020-09-17 17:18 ` John Snow
2020-09-18 10:55 ` Markus Armbruster
2020-09-18 16:08 ` John Snow
2020-09-21 7:43 ` Markus Armbruster
2020-09-15 22:40 ` [PATCH 10/37] qapi/common.py: delint with pylint John Snow
2020-09-17 14:15 ` Markus Armbruster
2020-09-17 17:48 ` John Snow
2020-09-18 11:03 ` Markus Armbruster
2020-09-15 22:40 ` [PATCH 11/37] qapi/common.py: Replace one-letter 'c' variable John Snow
2020-09-17 14:17 ` Markus Armbruster
2020-09-17 17:51 ` John Snow
2020-09-15 22:40 ` [PATCH 12/37] qapi/common.py: check with pylint John Snow
2020-09-15 22:40 ` [PATCH 13/37] qapi/common.py: add notational type hints John Snow
2020-09-17 14:32 ` Markus Armbruster
2020-09-17 18:18 ` John Snow
2020-09-17 20:06 ` John Snow
2020-09-18 11:14 ` Markus Armbruster
2020-09-18 15:24 ` John Snow
2020-09-15 22:40 ` [PATCH 14/37] qapi/common.py: Move comments into docstrings John Snow
2020-09-17 14:37 ` Markus Armbruster
2020-09-17 18:44 ` John Snow
2020-09-17 19:14 ` Eduardo Habkost
2020-09-17 19:31 ` John Snow
2020-09-24 15:06 ` Markus Armbruster
2020-09-24 16:31 ` John Snow
2020-09-25 7:49 ` Markus Armbruster
2020-09-25 14:07 ` John Snow
2020-09-15 22:40 ` [PATCH 15/37] qapi/common.py: split build_params into new file John Snow
2020-09-17 14:42 ` Markus Armbruster
2020-09-17 18:53 ` John Snow
2020-09-17 19:40 ` John Snow
2020-09-15 22:40 ` [PATCH 16/37] qapi: establish mypy type-checking baseline John Snow
2020-09-18 11:55 ` Markus Armbruster
2020-09-18 14:27 ` John Snow
2020-09-21 8:05 ` Markus Armbruster
2020-09-21 14:41 ` John Snow [this message]
2020-09-25 1:18 ` Eduardo Habkost
2020-09-18 19:03 ` John Snow
2020-09-21 8:05 ` Markus Armbruster
2020-09-21 14:46 ` John Snow
2020-09-15 22:40 ` [PATCH 17/37] qapi/events.py: add notational type hints John Snow
2020-09-15 22:40 ` [PATCH 18/37] qapi/events.py: Move comments into docstrings John Snow
2020-09-15 22:40 ` [PATCH 19/37] qapi/commands.py: Don't re-bind to variable of different type John Snow
2020-09-15 22:40 ` [PATCH 20/37] qapi/commands.py: add notational type hints John Snow
2020-09-15 22:40 ` [PATCH 21/37] qapi/commands.py: enable checking with mypy John Snow
2020-09-15 22:40 ` [PATCH 22/37] qapi/source.py: add notational type hints John Snow
2020-09-15 22:40 ` [PATCH 23/37] qapi/source.py: delint with pylint John Snow
2020-09-15 22:40 ` [PATCH 24/37] qapi/gen.py: Fix edge-case of _is_user_module John Snow
2020-09-15 22:40 ` [PATCH 25/37] qapi/gen.py: add notational type hints John Snow
2020-09-15 22:40 ` [PATCH 26/37] qapi/gen.py: Enable checking with mypy John Snow
2020-09-15 22:40 ` [PATCH 27/37] qapi/gen.py: Remove unused parameter John Snow
2020-09-15 22:40 ` [PATCH 28/37] qapi/gen.py: update write() to be more idiomatic John Snow
2020-09-15 22:40 ` [PATCH 29/37] qapi/gen.py: delint with pylint John Snow
2020-09-15 22:40 ` [PATCH 30/37] qapi/introspect.py: Add a typed 'extra' structure John Snow
2020-09-15 22:40 ` [PATCH 31/37] qapi/introspect.py: add _gen_features helper John Snow
2020-09-15 22:40 ` [PATCH 32/37] qapi/introspect.py: create a typed 'Node' data structure John Snow
2020-09-15 22:40 ` [PATCH 33/37] qapi/introspect.py: add notational type hints John Snow
2020-09-15 22:40 ` [PATCH 34/37] qapi/types.py: " John Snow
2020-09-15 22:40 ` [PATCH 35/37] qapi/types.py: remove one-letter variables John Snow
2020-09-15 22:40 ` [PATCH 36/37] qapi/visit.py: remove unused parameters from gen_visit_object John Snow
2020-09-15 22:40 ` [PATCH 37/37] qapi/visit.py: add notational type hints John Snow
2020-09-16 22:33 ` [PATCH 00/37] qapi: static typing conversion, pt1 John Snow
2020-09-17 20:22 ` John Snow
2020-09-18 7:50 ` Markus Armbruster
2020-09-18 13:07 ` Philippe Mathieu-Daudé
2020-09-18 14:30 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=510ead18-a91c-8d25-880a-99a9d628a25e@redhat.com \
--to=jsnow@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).