[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: |
Markus Armbruster |
Subject: |
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations |
Date: |
Thu, 08 Oct 2020 09:41:07 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
John Snow <jsnow@redhat.com> writes:
> 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
I now understand we can omit -> None, except when it's the only type
hint, because omitting it then would make it untyped, which is not what
we want.
Is this just for __init__(), or is it for any function that doesn't
return anything?
- 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, 2020/10/07
Re: [PATCH v5 19/36] qapi/events.py: add type hint annotations,
Markus Armbruster <=
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
[PATCH v5 25/36] qapi/source.py: delint with pylint, John Snow, 2020/10/05