Skip to content

qapi: static typing conversion, pt2

John Snow qemu-devel 11 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 posting 2/217 patches 1 replyIn review
  2. v2 posting 3/38 patches 13 repliesSuperseded
  3. v4 posting 2/219 patches 39 repliesSuperseded
Earlier versions · 8
VersionPostedPatchesRepliesStatus
v3 posting 2/216 patches37 repliesSuperseded
v6 Latest19 patches22 repliesIn review
v5 posting 1/215 patches11 repliesSuperseded
v4 posting 1/214 patches25 repliesSuperseded
v3 posting 1/213 patches0 repliesSuperseded
v2 posting 2/316 patches9 repliesSuperseded
v2 posting 1/311 patches36 repliesSuperseded
v125 patches1 replySuperseded

V4 from the cover letter

- Rebased on "pt1.5" v4
- signatures updated to use Optional[QAPISourceInfo]

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/19qapi: Replace List[str] with Sequence[str] for ifcondscripts/qapi/commands.py scripts/qapi/events.py scripts/qapi/gen.py +2 more+21 -203 replies
2/19qapi/introspect.py: assert schema is not Nonescripts/qapi/introspect.py+5 -00 replies
3/19qapi/introspect.py: use _make_tree for features nodesscripts/qapi/introspect.py+3 -10 replies
4/19qapi/introspect.py: add _gen_features helperscripts/qapi/introspect.py+12 -80 replies
5/19qapi/introspect.py: guard against ifcond/comment misusescripts/qapi/introspect.py+8 -21 reply
6/19qapi/introspect.py: Unify return type of _make_tree()scripts/qapi/introspect.py+1 -30 replies
7/19qapi/introspect.py: replace 'extra' dict with 'comment' argumentscripts/qapi/introspect.py+9 -60 replies
8/19qapi/introspect.py: Always define all 'extra' dict keysscripts/qapi/introspect.py+4 -50 replies
9/19qapi/introspect.py: Introduce preliminary tree typingscripts/qapi/introspect.py+30 -10 replies
10/19qapi/introspect.py: create a typed 'Annotated' data strutcurescripts/qapi/introspect.py+45 -330 replies
11/19qapi/introspect.py: improve _tree_to_qlit error messagescripts/qapi/introspect.py+3 -10 replies
12/19qapi/introspect.py: improve readability of _tree_to_qlitscripts/qapi/introspect.py+18 -150 replies
13/19qapi/introspect.py: remove _gen_variants helperscripts/qapi/introspect.py+2 -70 replies
14/19qapi/introspect.py: add type hint annotationsscripts/qapi/introspect.py scripts/qapi/mypy.ini scripts/qapi/schema.py+92 -398 replies
15/19qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlitscripts/qapi/introspect.py+18 -05 replies
16/19qapi/introspect.py: Update copyright and authors listscripts/qapi/introspect.py+2 -10 replies
17/19qapi/introspect.py: Type _gen_tree variants as Sequence[str]scripts/qapi/introspect.py+6 -52 replies
18/19qapi/introspect.py: set _gen_tree's default ifcond argument to ()scripts/qapi/introspect.py+2 -20 replies
19/19qapi/introspect.py: add SchemaMetaType enumscripts/qapi/introspect.py+29 -93 replies

Reviews trailers per patch

2 of 19 patches have a Reviewed-by or Acked-by.

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

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

Read the v6 thread

Cover letter [PATCH v6 00/19] qapi: static typing conversion, pt2

Hi, this series adds static type hints to the QAPI module. This is part two, and covers introspect.py.

Part 2: https://gitlab.com/jsnow/qemu/-/tree/python-qapi-cleanup-pt2
Everything: https://gitlab.com/jsnow/qemu/-/tree/python-qapi-cleanup-pt6

- Requires Python 3.6+
- Requires mypy 0.770 or newer (for type analysis only)
- Requires pylint 2.6.0 or newer (for lint checking only)

(Note: pylint does not like Python 3.9 very much yet. Known problem.)

Type hints are added in patches that add *only* type hints and change no other behavior. Any necessary changes to behavior to accommodate typing are split out into their own tiny patches.

Every commit should pass with (from ./scripts):
- flake8 qapi/
- pylint --rcfile=qapi/pylintrc qapi/
- mypy --config-file=qapi/mypy.ini qapi/
- isort -c qapi/

V6:

001/19:[down] 'qapi: Replace List[str] with Sequence[str] for ifcond' 009/19:[0021] [FC] 'qapi/introspect.py: Introduce preliminary tree typing' 010/19:[0013] [FC] 'qapi/introspect.py: create a typed 'Annotated' data strutcure' 013/19:[down] 'qapi/introspect.py: remove _gen_variants helper' 014/19:[0053] [FC] 'qapi/introspect.py: add type hint annotations' 015/19:[down] 'qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit' 017/19:[down] 'qapi/introspect.py: Type _gen_tree variants as Sequence[str]' 018/19:[down] 'qapi/introspect.py: set _gen_tree's default ifcond argument to ()' 019/19:[down] 'qapi/introspect.py: add SchemaMetaType enum'

01: New; consistently type ifcond as Seq[str] in already-typed files. 09: Adjust comment concerning _stub to be more clear (?)
Rename _stub to _Stub, etc.
TreeValue becomes JSONValue.
10: _NodeT becomes _ValueT to match the _Value name.
Change visit_alternate_type whitespace around some more.
13: New, pre-requisite for using SchemaInfo aliases.
(Was not appropriate to go into #14.)
14: Use Sequence[str] instead of List[str] for ifcond
Use SchemaInfo "dummy types" instead of _DObject
15: Adjust comment to mention dict_value limitation.
Add docstring for _gen_tree (from former "dummy types" patch). Change name of commit to reflect now-multiple docstring additions.

OPTIONAL PATCHES:

17: Use Sequence[QAPISchemaFeature] instead of Optional[List[QAPISchemaFeature]] 18: Set a default argument for ifcond to the empty tuple ().
Stylistically matches the above patch.
19: Create a SchemaMetaType enum and use it instead of the string type.
(Contains an optional blurb that can be removed if desired.)

V5:

04: Rename 'suppress_first_indent' to 'dict_value'
(Docstring added in 014.)
06: Avoid changing the output structure of _make_tree
07: Chance the structure of _make_tree 8-)
08: Change commented TreeValue to include a TODO instead.
09: Change NodeT bound to _value instead of TreeValue
Change "Remove in 3.7" text to include "TODO: "
Remove forwarding suppress_first_indent/dict_value in recursive cases Change spacing in visit_alternate_type()
11: Consequence of suppress_first_value/dict_value change
12: Commit message note added
Changed _DObject comment
13: Commit notes adjusted
_DObject stuff: Comment near SchemaInfo et al adjusted
14: Changed docstring to reflect dict_value change
15: Updated copyright year for 2021 :~)

V4:
- Rebased on "pt1.5" v4
- signatures updated to use Optional[QAPISourceInfo]

John Snow (19):
qapi: Replace List[str] with Sequence[str] for ifcond qapi/introspect.py: assert schema is not None qapi/introspect.py: use _make_tree for features nodes qapi/introspect.py: add _gen_features helper qapi/introspect.py: guard against ifcond/comment misuse qapi/introspect.py: Unify return type of _make_tree() qapi/introspect.py: replace 'extra' dict with 'comment' argument qapi/introspect.py: Always define all 'extra' dict keys qapi/introspect.py: Introduce preliminary tree typing qapi/introspect.py: create a typed 'Annotated' data strutcure qapi/introspect.py: improve _tree_to_qlit error message qapi/introspect.py: improve readability of _tree_to_qlit qapi/introspect.py: remove _gen_variants helper qapi/introspect.py: add type hint annotations qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit qapi/introspect.py: Update copyright and authors list qapi/introspect.py: Type _gen_tree variants as Sequence[str] qapi/introspect.py: set _gen_tree's default ifcond argument to () qapi/introspect.py: add SchemaMetaType enum

 scripts/qapi/commands.py   |   3 +-
 scripts/qapi/events.py     |   4 +-
 scripts/qapi/gen.py        |  12 +-
 scripts/qapi/introspect.py | 350 +++++++++++++++++++++++++++----------
 scripts/qapi/mypy.ini      |   5 -
 scripts/qapi/schema.py     |   2 +-
 scripts/qapi/types.py      |  12 +-
 scripts/qapi/visit.py      |  10 +-
 8 files changed, 275 insertions(+), 123 deletions(-)
Signature · 1 line
2.29.2