Skip to content

qapi: static typing conversion, pt1.5

John Snow qemu-devel 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest16 patches 6 repliesIn review
  2. v317 patches 11 repliesSuperseded
  3. v212 patches 13 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v112 patches28 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16qapi/commands: assert arg_type is not Nonescripts/qapi/commands.py+6 -30 replies
2/16qapi/events: fix visit_event typingscripts/qapi/events.py+7 -50 replies
3/16qapi/main: handle theoretical None-return from re.match()scripts/qapi/main.py+2 -00 replies
4/16qapi/gen: inline _wrap_ifcond into end_if()scripts/qapi/gen.py+2 -50 replies
5/16qapi: centralize is_[user|system|builtin]_module methodsscripts/qapi/gen.py scripts/qapi/schema.py+40 -162 replies
6/16qapi/gen: Replace ._begin_system_module()scripts/qapi/gen.py scripts/qapi/types.py scripts/qapi/visit.py+7 -60 replies
7/16qapi: use explicitly internal module namesscripts/qapi/commands.py scripts/qapi/events.py scripts/qapi/gen.py+4 -33 replies
8/16qapi: use './builtin' as the built-in module namescripts/qapi/gen.py scripts/qapi/schema.py tests/qapi-schema/comments.out +7 more+27 -270 replies
9/16qapi/gen: Combine ._add_[user|system]_modulescripts/qapi/commands.py scripts/qapi/events.py scripts/qapi/gen.py+7 -140 replies
10/16qapi: centralize the built-in module name definitionscripts/qapi/schema.py+8 -50 replies
11/16qapi/gen: write _genc/_genh access shimsscripts/qapi/gen.py+13 -50 replies
12/16qapi/gen: Support for switching to another module temporarilyscripts/qapi/gen.py+7 -00 replies
13/16qapi/commands: Simplify command registry generationscripts/qapi/commands.py+22 -270 replies
14/16qapi/gen: Drop support for QAPIGen without a file namescripts/qapi/gen.py+2 -20 replies
15/16qapi: type 'info' as Optional[QAPISourceInfo]scripts/qapi/commands.py scripts/qapi/events.py scripts/qapi/gen.py +2 more+6 -60 replies
16/16qapi: enable strict-optional checksscripts/qapi/mypy.ini+0 -10 replies

Reviews trailers per patch

None of the 16 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMarkus Armbruster
SeriesR-b
1/16
2/16
3/16
4/16
5/16
6/16
7/16
8/16
9/16
10/16
11/16
12/16
13/16
14/16
15/16
16/16

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 00/16] qapi: static typing conversion, pt1.5

Hi, this patchset enables strict optional checking in mypy for everything we have typed so far.

In general, this patchset seeks to clarify Optional[T] vs T and lift the no-strict-optional restriction in mypy.

Ironing out these issues allows us to be even stricter with our type checking, which improves consistency in subclass interface types and should make review a little nicer.

This series is based on (but does not require) the 'qapi: sphinx-autodoc for qapi module' series.

V4:

001/16:[----] [--] 'qapi/commands: assert arg_type is not None' 002/16:[----] [--] 'qapi/events: fix visit_event typing' 003/16:[----] [--] 'qapi/main: handle theoretical None-return from re.match()' 004/16:[----] [--] 'qapi/gen: inline _wrap_ifcond into end_if()' 005/16:[0047] [FC] 'qapi: centralize is_[user|system|builtin]_module methods' 006/16:[0007] [FC] 'qapi/gen: Replace ._begin_system_module()' 007/16:[----] [--] 'qapi: use explicitly internal module names' 008/16:[0016] [FC] 'qapi: use './builtin' as the built-in module name' 009/16:[0011] [FC] 'qapi/gen: Combine ._add_[user|system]_module' 010/16:[0008] [FC] 'qapi: centralize the built-in module name definition' 011/16:[----] [-C] 'qapi/gen: write _genc/_genh access shims' 012/16:[----] [--] 'qapi/gen: Support for switching to another module temporarily' 013/16:[----] [--] 'qapi/commands: Simplify command registry generation' 014/16:[----] [--] 'qapi/gen: Drop support for QAPIGen without a file name' 015/16:[----] [-C] 'qapi: type 'info' as Optional[QAPISourceInfo]' 016/16:[----] [--] 'qapi: enable strict-optional checks'

Removed the patch that made visit_module work in terms of QAPISchemaModule instead of the module name.

05: Remove the properties, keep just the static/classmethods.
Convert classmethod to staticmethod where possible.
Add docstrings to alleviate confusion about what these methods do. Leave qapidoc generator alone for now.
Remove future-bleed from is_system_module (check for None, not "./builtin")

06: Change the conditionals in gen.py visit_module to use is_builtin_module.

08: Some contextual difference now that modules are no longer being passed
via visit_module.
Code added by patch 05 is now amended here to make it consistent in history.

09: Removed assertion. Changed commit message.

10: Contextual fallout; removed end-of-line comment that was unneeded.

Notes:

Admittedly, at this point it feels like style and taste. I played with several other alternatives, but felt I wasn't making good progress in any direction that was more defensible than what I have here.

If there are nits at this point, I think they generally require more engineering than what is present here to resolve them satisfactorily; to that end I feel like this is close to the fewest SLOC changes that felt defensible. Concrete counter-proposals would be preferred to minimize guess-work when it comes to matters of style.

Namely, I would vastly prefer "module.system_module" as a property of the module object and to pass those to visitors, but the work involved in doing this is not trivial, because the generators that "add a system module" generally only add a system module *name* to the generator, as if it was visited -- but this is an emulated behavior as a code-generation technique, the module does not exist. Changing the gen.py functions to *actually* create a module is more hassle than it is worth at present, so that python module ought to remain working in terms of module *names*. Renaming the functions to reflect that made them a little too cumbersome/long for my tastes, so I left them alone.

However, I still felt it important to begin making the claim that module namespaces are global and shared between the generator and the schema; so I still opted to use QAPISchemaModule methods to formalize the module type definitions, even if we aren't using them in a classy way (yet).

You may argue that these can be functions instead, and they can; but it is just an organizational preference that they live within the QAPISchemaModule namespace because (to me) this solidifies the idea that schema.py and QAPISchemaModule themselves are the solely responsible entities for these definitions. (i.e., it makes it clear to me that these namespaces aren't purely an invention of gen.py -- which they can no longer be, as we are declaring and naming "./builtin", the built-in schema module that contains our predefined types in schema.py.)

I didn't think it was worth making a class for the names alone and going that route; that felt like more work than was warranted, too. So this represents roughly the bottom floor of what seemed subjectively sensible.

--js

John Snow (11):
qapi/commands: assert arg_type is not None qapi/events: fix visit_event typing
qapi/main: handle theoretical None-return from re.match() qapi/gen: inline _wrap_ifcond into end_if()
qapi: centralize is_[user|system|builtin]_module methods
qapi: use explicitly internal module names
qapi: use './builtin' as the built-in module name
qapi: centralize the built-in module name definition qapi/gen: write _genc/_genh access shims
qapi: type 'info' as Optional[QAPISourceInfo]
qapi: enable strict-optional checks

Markus Armbruster (5):
qapi/gen: Replace ._begin_system_module()
qapi/gen: Combine ._add_[user|system]_module qapi/gen: Support for switching to another module temporarily qapi/commands: Simplify command registry generation qapi/gen: Drop support for QAPIGen without a file name

 scripts/qapi/commands.py                 | 62 ++++++++--------
 scripts/qapi/events.py                   | 16 ++--
 scripts/qapi/gen.py                      | 94 ++++++++++++------------
 scripts/qapi/main.py                     |  2 +
 scripts/qapi/mypy.ini                    |  1 -
 scripts/qapi/schema.py                   | 42 +++++++++--
 scripts/qapi/types.py                    |  4 +-
 scripts/qapi/visit.py                    |  6 +-
 tests/qapi-schema/comments.out           |  2 +-
 tests/qapi-schema/doc-good.out           |  2 +-
 tests/qapi-schema/empty.out              |  2 +-
 tests/qapi-schema/event-case.out         |  2 +-
 tests/qapi-schema/include-repetition.out |  2 +-
 tests/qapi-schema/include-simple.out     |  2 +-
 tests/qapi-schema/indented-expr.out      |  2 +-
 tests/qapi-schema/qapi-schema-test.out   |  2 +-
 16 files changed, 139 insertions(+), 104 deletions(-)
Signature · 1 line
2.29.2