[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations
From: |
John Snow |
Subject: |
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations |
Date: |
Wed, 7 Oct 2020 11:39:28 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 |
On 10/7/20 7:32 AM, Markus Armbruster wrote:
Ignorant question: what's the difference between -> None (like here) and
nothing (like __init__() above?
This came up in Cleber's review, too.
Mypy supports a gradual typing paradigm; it is designed to facilitate
what we are doing here: the gradual adding of types until we are able to
enforce static typing everywhere.
To that end, mypy uses a simple heuristic to determine if a function is
"typed" or "untyped": did you use any type annotations for it?
Meanwhile, __init__ never returns anything. You do not need to annotate
its return type. mypy knows what the return type is and must be. In the
case of __init__ with no parameters, it is both untyped and strictly typed!
Annotating the return type for no-parameter init methods convinces mypy
that this is a strictly typed method. It doesn't do this automatically,
because doing so might enable more checks than you were ready for simply
because mypy was able to accurately surmise the typing of just __init__.
So it's just a little flip switch to enable strict typing, really.
--js
https://mypy.readthedocs.io/en/stable/class_basics.html#annotating-init-methods
- Re: [PATCH v5 18/36] qapi: establish mypy type-checking baseline, (continued)
[PATCH v5 19/36] qapi/events.py: add type hint annotations, John Snow, 2020/10/05
- Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, Markus Armbruster, 2020/10/07
- Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, Markus Armbruster, 2020/10/07
- Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, John Snow, 2020/10/07
- Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, Markus Armbruster, 2020/10/08
- Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, John Snow, 2020/10/08
- Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, Markus Armbruster, 2020/10/09
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations,
John Snow <=
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, Markus Armbruster, 2020/10/08
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations, John Snow, 2020/10/08
[PATCH v5 20/36] qapi/events.py: Move comments into docstrings, John Snow, 2020/10/05
[PATCH v5 22/36] qapi/commands.py: add type hint annotations, John Snow, 2020/10/05
[PATCH v5 21/36] qapi/commands.py: Don't re-bind to variable of different type, John Snow, 2020/10/05
[PATCH v5 23/36] qapi/commands.py: enable checking with mypy, John Snow, 2020/10/05