qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [qemu/qemu] ec9697: qapi/commands: assert arg_type is not


From: Peter Maydell
Subject: [Qemu-commits] [qemu/qemu] ec9697: qapi/commands: assert arg_type is not None
Date: Mon, 08 Feb 2021 09:33:19 -0800

  Branch: refs/heads/master
  Home:   https://github.com/qemu/qemu
  Commit: ec9697ab3fe2174a865d0ac2bbc572cbd5981d94
      
https://github.com/qemu/qemu/commit/ec9697ab3fe2174a865d0ac2bbc572cbd5981d94
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/commands.py

  Log Message:
  -----------
  qapi/commands: assert arg_type is not None

When boxed is True, expr.py asserts that we must have
arguments. Ultimately, this should mean that if boxed is True that
arg_type should be defined. Mypy cannot infer this, and does not support
'stateful' type inference, e.g.:

```
if x:
    assert y is not None

...

if x:
    y.etc()
```

does not work, because mypy does not statefully remember the conditional
assertion in the second block. Help mypy out by creating a new local
that it can track more easily.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-2-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: 3cc01c546ba508222e0ccda775bce30e07c0461f
      
https://github.com/qemu/qemu/commit/3cc01c546ba508222e0ccda775bce30e07c0461f
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/events.py

  Log Message:
  -----------
  qapi/events: fix visit_event typing

Actually, the arg_type can indeed be Optional.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-3-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: ad1218086efb469d292f5cdd3e8299e5d2e7d8d6
      
https://github.com/qemu/qemu/commit/ad1218086efb469d292f5cdd3e8299e5d2e7d8d6
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/main.py

  Log Message:
  -----------
  qapi/main: handle theoretical None-return from re.match()

Mypy cannot understand that this match can never be None, so help it
along.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-4-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: a253b3eb9a194a0b2e8b55095ce5f28c2d5cfa11
      
https://github.com/qemu/qemu/commit/a253b3eb9a194a0b2e8b55095ce5f28c2d5cfa11
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py

  Log Message:
  -----------
  qapi/gen: inline _wrap_ifcond into end_if()

We assert _start_if is not None in end_if, but that's opaque to mypy.
By inlining _wrap_ifcond, that constraint becomes provable to mypy.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-5-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: 98967c248c4c01085af2ff49ed3d378f79019902
      
https://github.com/qemu/qemu/commit/98967c248c4c01085af2ff49ed3d378f79019902
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py
    M scripts/qapi/schema.py

  Log Message:
  -----------
  qapi: centralize is_[user|system|builtin]_module methods

Define what a module is and define what kind of a module it is once and
for all, in one place.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-6-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: f3a705928a7b1825678ff510843702652bc15f1a
      
https://github.com/qemu/qemu/commit/f3a705928a7b1825678ff510843702652bc15f1a
  Author: Markus Armbruster <armbru@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py
    M scripts/qapi/types.py
    M scripts/qapi/visit.py

  Log Message:
  -----------
  qapi/gen: Replace ._begin_system_module()

QAPISchemaModularCVisitor._begin_system_module() is actually just for
the builtin module.  Rename it to ._begin_builtin_module() and drop
its useless @name parameter.

Clarify conditionals in visit_module to make this clear.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-7-jsnow@redhat.com>


  Commit: 12893a8ea7163e871abae05b5a42cdce1ad45225
      
https://github.com/qemu/qemu/commit/12893a8ea7163e871abae05b5a42cdce1ad45225
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/commands.py
    M scripts/qapi/events.py
    M scripts/qapi/gen.py

  Log Message:
  -----------
  qapi: use explicitly internal module names

QAPISchemaModularCVisitor._add_system_module() prefixes './' to its name
argument to make it a module name.  Pass the module name instead.  This
will allow us to coalesce the methods to add modules later on.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-8-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Commit message reworded]
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: e2bbc4eaa7f0d8efb8f49705bae0fecd3356f417
      
https://github.com/qemu/qemu/commit/e2bbc4eaa7f0d8efb8f49705bae0fecd3356f417
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py
    M scripts/qapi/schema.py
    M tests/qapi-schema/comments.out
    M tests/qapi-schema/doc-good.out
    M tests/qapi-schema/empty.out
    M tests/qapi-schema/event-case.out
    M tests/qapi-schema/include-repetition.out
    M tests/qapi-schema/include-simple.out
    M tests/qapi-schema/indented-expr.out
    M tests/qapi-schema/qapi-schema-test.out

  Log Message:
  -----------
  qapi: use './builtin' as the built-in module name

Use './builtin' as the built-in module name instead of
None. Clarify the typing that this is now always a string.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-9-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: 4ab0ff6da0828e6499d633a4801f4e6b6e96d21b
      
https://github.com/qemu/qemu/commit/4ab0ff6da0828e6499d633a4801f4e6b6e96d21b
  Author: Markus Armbruster <armbru@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/commands.py
    M scripts/qapi/events.py
    M scripts/qapi/gen.py

  Log Message:
  -----------
  qapi/gen: Combine ._add_[user|system]_module

With callers to _add_system_module now explicitly using the './' prefix
to indicate a system module, there is no longer any reason to have
separate interfaces for adding system vs user modules; use a unified
interface that differentiates based on the name.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-10-jsnow@redhat.com>


  Commit: 39b2d838f1f8a6c3d2fc4e2eecc45e5554d02af7
      
https://github.com/qemu/qemu/commit/39b2d838f1f8a6c3d2fc4e2eecc45e5554d02af7
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/schema.py

  Log Message:
  -----------
  qapi: centralize the built-in module name definition

Use a constant to make it obvious we're referring to a very specific thing.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-11-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: fd9b1603843df86b430083b583157fe0c352901e
      
https://github.com/qemu/qemu/commit/fd9b1603843df86b430083b583157fe0c352901e
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py

  Log Message:
  -----------
  qapi/gen: write _genc/_genh access shims

Many places assume they can access these fields without checking them
first to ensure they are defined. Eliminating the _genc and _genh fields
and replacing them with functional properties that check for correct
state can ease the typing overhead by eliminating the Optional[T] return
type.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-12-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: d921d27c1bac0765370a9b9b891f9f0429f4c7c3
      
https://github.com/qemu/qemu/commit/d921d27c1bac0765370a9b9b891f9f0429f4c7c3
  Author: Markus Armbruster <armbru@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py

  Log Message:
  -----------
  qapi/gen: Support switching to another module temporarily

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-13-jsnow@redhat.com>
[Commit message tweaked]


  Commit: c6cd7e4151794194f804ac3b8d2bc9347142c024
      
https://github.com/qemu/qemu/commit/c6cd7e4151794194f804ac3b8d2bc9347142c024
  Author: Markus Armbruster <armbru@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/commands.py

  Log Message:
  -----------
  qapi/commands: Simplify command registry generation

QAPISchemaGenCommandVisitor.visit_command() needs to generate the
marshalling function into the current module, and also generate its
registration into the ./init system module.  The latter is done
somewhat awkwardly: .__init__() creates a QAPIGenCCode that will not
be written out, each .visit_command() adds its registration to it, and
.visit_end() copies its contents into the ./init module it creates.

Instead provide the means to temporarily switch to another module.
Create the ./init module in .visit_begin(), and generate its initial
part.  Add registrations to it in .visit_command().  Finish it in
.visit_end().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-14-jsnow@redhat.com>


  Commit: cc0747f6b709c197b077cd313f37617fc80c3be1
      
https://github.com/qemu/qemu/commit/cc0747f6b709c197b077cd313f37617fc80c3be1
  Author: Markus Armbruster <armbru@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/gen.py

  Log Message:
  -----------
  qapi/gen: Drop support for QAPIGen without a file name

The previous commit removed the only user of QAPIGen(None).  Tighten
the type hint.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-15-jsnow@redhat.com>


  Commit: 4a82e468e76f67901a7fcaeaf2d31904664658cc
      
https://github.com/qemu/qemu/commit/4a82e468e76f67901a7fcaeaf2d31904664658cc
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/commands.py
    M scripts/qapi/events.py
    M scripts/qapi/gen.py
    M scripts/qapi/types.py
    M scripts/qapi/visit.py

  Log Message:
  -----------
  qapi: type 'info' as Optional[QAPISourceInfo]

For everything typed so far, type this parameter as
Optional[QAPISourceInfo].

In the most generic case, QAPISchemaEntity's info field may be None to
represent types that come from built-in definitions. Although some
Entity types may not currently have any built-in definitions, it is not
easily possible to constrain the type except on an ad-hoc basis using
assertions.

It's easier and simpler, then, to just say it's always an Optional type.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-16-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: c51172667b64abc570640f141ca3bf7109fbbd17
      
https://github.com/qemu/qemu/commit/c51172667b64abc570640f141ca3bf7109fbbd17
  Author: John Snow <jsnow@redhat.com>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/mypy.ini

  Log Message:
  -----------
  qapi: enable strict-optional checks

In the modules that we are checking so far, we can be stricter about the
difference between Optional[T] and T types. Enable that check.

Enabling it now will assist review on further typing and cleanup work.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-17-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>


  Commit: 4f799257b323e1238a900fd0c71c2057863e0308
      
https://github.com/qemu/qemu/commit/4f799257b323e1238a900fd0c71c2057863e0308
  Author: Peter Maydell <peter.maydell@linaro.org>
  Date:   2021-02-08 (Mon, 08 Feb 2021)

  Changed paths:
    M scripts/qapi/commands.py
    M scripts/qapi/events.py
    M scripts/qapi/gen.py
    M scripts/qapi/main.py
    M scripts/qapi/mypy.ini
    M scripts/qapi/schema.py
    M scripts/qapi/types.py
    M scripts/qapi/visit.py
    M tests/qapi-schema/comments.out
    M tests/qapi-schema/doc-good.out
    M tests/qapi-schema/empty.out
    M tests/qapi-schema/event-case.out
    M tests/qapi-schema/include-repetition.out
    M tests/qapi-schema/include-simple.out
    M tests/qapi-schema/indented-expr.out
    M tests/qapi-schema/qapi-schema-test.out

  Log Message:
  -----------
  Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-02-08' into 
staging

QAPI patches patches for 2021-02-08

# gpg: Signature made Mon 08 Feb 2021 13:54:26 GMT
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-qapi-2021-02-08:
  qapi: enable strict-optional checks
  qapi: type 'info' as Optional[QAPISourceInfo]
  qapi/gen: Drop support for QAPIGen without a file name
  qapi/commands: Simplify command registry generation
  qapi/gen: Support switching to another module temporarily
  qapi/gen: write _genc/_genh access shims
  qapi: centralize the built-in module name definition
  qapi/gen: Combine ._add_[user|system]_module
  qapi: use './builtin' as the built-in module name
  qapi: use explicitly internal module names
  qapi/gen: Replace ._begin_system_module()
  qapi: centralize is_[user|system|builtin]_module methods
  qapi/gen: inline _wrap_ifcond into end_if()
  qapi/main: handle theoretical None-return from re.match()
  qapi/events: fix visit_event typing
  qapi/commands: assert arg_type is not None

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Compare: https://github.com/qemu/qemu/compare/8eef07b4d3c2...4f799257b323



reply via email to

[Prev in Thread] Current Thread [Next in Thread]