summaryrefslogtreecommitdiffstats
path: root/scripts/qapi
Commit message (Collapse)AuthorAgeFilesLines
* qapi: Fix parse errors for removal of null from schema languageMarkus Armbruster2021-03-051-4/+4
| | | | | | | | | | Commit 9d55380b5a "qapi: Remove null from schema language" (v4.2.0) neglected to update two error messages. Do that now. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20210224101442.1837475-1-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
* qapi/introspect.py: set _gen_tree's default ifcond argument to ()John Snow2021-02-181-2/+2
| | | | | | | | | | | We don't need to create an empty, mutable list to pass to _gen_tree; since it is now typed as a Sequence, we can use the empty tuple as a default and omit the argument. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-19-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: Type _gen_tree variants as Sequence[str]John Snow2021-02-181-4/+4
| | | | | | | | | | | | | Optional[List] is clunky; an empty sequence can more elegantly convey "no variants". By downgrading "List" to "Sequence", we can also accept tuples; this is useful for the empty tuple specifically, which we may use as a default parameter because it is immutable. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-18-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Doc string touched up] Reviewed-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: Update copyright and authors listJohn Snow2021-02-181-1/+2
| | | | | | | | | | To reflect the work that went into strictly typing introspect.py, punish myself by claiming credit. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-17-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlitJohn Snow2021-02-181-0/+20
| | | | | | | | Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-16-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Doc string improvements squashed in] Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: add type hint annotationsJohn Snow2021-02-183-39/+93
| | | | | | | | | | | | | | | | | | | NB: The type aliases (SchemaInfo et al) declare intent for some of the "dictly-typed" objects we pass around in introspect.py. They do not enforce the shape of those objects, and cannot, until Python 3.7 or later. (And even then, it may not be "worth it".) Annotations are also added to the QAPISchemaEntity __init__ method in schema.py to allow mypy to statically prove the type of typ.name, needed to prove the return type of QAPISchemaGenIntrospectVisitor._use_type(). Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-15-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Note on QAPISchemaEntity.__init__() squashed into commit message, Comment wrapped to conform to PEP 8] Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: remove _gen_variants helperJohn Snow2021-02-181-7/+2Star
| | | | | | | | | | | | | It is easier to give a name to all of the dictly-typed objects we pass around in introspect.py by removing this helper, as it does not return an object that has any knowable type by itself. Inline it into its only caller instead. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-14-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: improve readability of _tree_to_qlitJohn Snow2021-02-181-15/+18
| | | | | | | | | | | Subjective, but I find getting rid of the comprehensions helps. Also, divide the sections into scalar and non-scalar sections, and remove old-style string formatting. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-13-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: improve _tree_to_qlit error messageJohn Snow2021-02-181-1/+3
| | | | | | | | | | Trivial; make the error message just a pinch more explicit in case we trip this by accident in the future. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-12-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: create a typed 'Annotated' data strutcureJohn Snow2021-02-181-33/+45
| | | | | | | | | | | | | | | | | Presently, we use a tuple to attach a dict containing annotations (comments and compile-time conditionals) to a tree node. This is undesirable because dicts are difficult to strongly type; promoting it to a real class allows us to name the values and types of the annotations we are expecting. In terms of typing, the Annotated<T> type serves as a generic container where the annotated node's type is preserved, allowing for greater specificity than we'd be able to provide without a generic. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-11-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: Introduce preliminary tree typingJohn Snow2021-02-181-1/+30
| | | | | | | | | | | | The types will be used in forthcoming patches to add typing. These types describe the layout and structure of the objects passed to _tree_to_qlit, but lack the power to describe annotations until the next commit. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-10-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: Always define all 'extra' dict keysJohn Snow2021-02-181-5/+4Star
| | | | | | | | | | | | | | | This mimics how a typed object works, where 'if' and 'comment' are always set, regardless of if they have a value set or not. It is safe to do this because of the way that _tree_to_qlit processes these values (using dict.get with a default of None), resulting in no change of output from _tree_to_qlit. There are no other users of this data. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-9-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: replace 'extra' dict with 'comment' argumentJohn Snow2021-02-181-6/+9
| | | | | | | | | | This is only used to pass in a dictionary with a comment already set, so skip the runaround and just accept the (optional) comment. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-8-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: Unify return type of _make_tree()John Snow2021-02-181-3/+1Star
| | | | | | | | | | Returning two different types conditionally can be complicated to type. Return one type for consistency. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-7-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: guard against ifcond/comment misuseJohn Snow2021-02-181-2/+9
| | | | | | | | | | | | | | | | | | _tree_to_qlit is called recursively on dict values (isolated from their keys); at such a point in generating output it is too late to apply an ifcond. Similarly, comments do not necessarily have a "tidy" place they can be printed in such a circumstance. Forbid this usage by renaming "suppress_first_indent" to "dict_value" to emphasize that indents are suppressed only for the benefit of dict values; then add an assertion assuring we do not pass ifcond/comments in this case. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-6-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Comment wrapped to conform to PEP 8] Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: add _gen_features helperJohn Snow2021-02-181-8/+12
| | | | | | | | | | | | _make_tree might receive a dict (a SchemaInfo object) or some other type (usually, a string) for its obj parameter. Adding features information should arguably be performed by the caller at such a time when we know the type of the object and don't have to re-interrogate it. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-5-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: use _make_tree for features nodesJohn Snow2021-02-181-1/+3
| | | | | | | | | | | | | | | | | At present, we open-code this in _make_tree itself; but if the structure of the tree changes, this is brittle. Use an explicit recursive call to _make_tree when appropriate to help keep the interior node typing consistent. A consequence of doing this is that the 'ifcond' key of the features dict will be omitted when ifcond is false-ish, just like it is omitted in top-level calls to _make_tree. This also increases consistency in our handling of this property. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-4-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/introspect.py: assert schema is not NoneJohn Snow2021-02-181-0/+5
| | | | | | | | | | The introspect visitor is stateful, but expects that it will have a schema to refer to. Add assertions that state this. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-3-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi: Replace List[str] with Sequence[str] for ifcondJohn Snow2021-02-185-20/+21
| | | | | | | | | | | | | | | It does happen to be a list (as of now), but we can describe it in more general terms with no loss in accuracy to allow tuples and other constructs. In the future, we can write "ifcond: Sequence[str] = ()" as a default parameter, which we could not do safely with a Mutable type like a List. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-2-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Commit message tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi: enable strict-optional checksJohn Snow2021-02-081-1/+0Star
| | | | | | | | | | | | 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>
* qapi: type 'info' as Optional[QAPISourceInfo]John Snow2021-02-085-6/+6
| | | | | | | | | | | | | | | | | | 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>
* qapi/gen: Drop support for QAPIGen without a file nameMarkus Armbruster2021-02-081-2/+2
| | | | | | | | | 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>
* qapi/commands: Simplify command registry generationMarkus Armbruster2021-02-081-27/+22Star
| | | | | | | | | | | | | | | | | | 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>
* qapi/gen: Support switching to another module temporarilyMarkus Armbruster2021-02-081-0/+7
| | | | | | | 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]
* qapi/gen: write _genc/_genh access shimsJohn Snow2021-02-081-5/+13
| | | | | | | | | | | | | 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>
* qapi: centralize the built-in module name definitionJohn Snow2021-02-081-5/+8
| | | | | | | | | 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>
* qapi/gen: Combine ._add_[user|system]_moduleMarkus Armbruster2021-02-083-14/+7Star
| | | | | | | | | | | 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>
* qapi: use './builtin' as the built-in module nameJohn Snow2021-02-082-19/+19
| | | | | | | | | | 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>
* qapi: use explicitly internal module namesJohn Snow2021-02-083-3/+4
| | | | | | | | | | | | 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>
* qapi/gen: Replace ._begin_system_module()Markus Armbruster2021-02-083-6/+7
| | | | | | | | | | | | 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>
* qapi: centralize is_[user|system|builtin]_module methodsJohn Snow2021-02-082-16/+40
| | | | | | | | | | 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>
* qapi/gen: inline _wrap_ifcond into end_if()John Snow2021-02-081-5/+2Star
| | | | | | | | | | 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>
* qapi/main: handle theoretical None-return from re.match()John Snow2021-02-081-0/+2
| | | | | | | | | | 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>
* qapi/events: fix visit_event typingJohn Snow2021-02-081-5/+7
| | | | | | | | | 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>
* qapi/commands: assert arg_type is not NoneJohn Snow2021-02-081-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* qapi/visit.py: add type hint annotationsJohn Snow2020-10-102-22/+56
| | | | | | | | | | | | | Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-37-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/visit.py: remove unused parameters from gen_visit_objectJohn Snow2020-10-102-3/+2Star
| | | | | | | | | | | | | | And this fixes the pylint report for this file, so make sure we check this in the future, too. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20201009161558.107041-36-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/visit.py: assert tag_member contains a QAPISchemaEnumTypeJohn Snow2020-10-101-5/+7
| | | | | | | | | | | | This is true by design, but not presently able to be expressed in the type system. An assertion helps mypy understand our constraints. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-35-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/types.py: remove one-letter variablesJohn Snow2020-10-102-15/+15
| | | | | | | | | | | | | | "John, if pylint told you to jump off a bridge, would you?" Hey, if it looked like fun, I might. Now that this file is clean, enable pylint checks on this file. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-34-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/types.py: add type hint annotationsJohn Snow2020-10-102-27/+64
| | | | | | | | | | | | Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-33-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/gen.py: delint with pylintJohn Snow2020-10-102-2/+5
| | | | | | | | | | | | | | | 'fp' and 'fd' are self-evident in context, add them to the list of OK names. _top and _bottom also need to stay standard methods because some users override the method and need to use `self`. Tell pylint to shush. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-32-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/gen.py: update write() to be more idiomaticJohn Snow2020-10-101-14/+11Star
| | | | | | | | | | | | | | | | Make the file handling here just a tiny bit more idiomatic. (I realize this is heavily subjective.) Use exist_ok=True for os.makedirs and remove the exception, use fdopen() to wrap the file descriptor in a File-like object, and use a context manager for managing the file pointer. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20201009161558.107041-31-jsnow@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/gen.py: Remove unused parameterJohn Snow2020-10-101-2/+2
| | | | | | | | | | | _module_dirname doesn't use the 'what' argument, so remove it. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-30-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/gen.py: add type hint annotationsJohn Snow2020-10-102-52/+57
| | | | | | | | | | | | | | Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-28-jsnow@redhat.com> Message-Id: <20201009161558.107041-29-jsnow@redhat.com> [mypy.ini update squashed in] Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/gen: Make _is_user_module() return boolJohn Snow2020-10-101-1/+1
| | | | | | | | | | | | | | _is_user_module() returns thruth values. The next commit wants it to return bool. Make it so. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20201009161558.107041-27-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Commit message rewritten] Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/source.py: delint with pylintJohn Snow2020-10-102-1/+3
| | | | | | | | | | | | | Shush an error and leave a hint for future cleanups when we're allowed to use Python 3.7+. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-26-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/source.py: add type hint annotationsJohn Snow2020-10-102-18/+19
| | | | | | | | | | | | | | | | | | | | Annotations do not change runtime behavior. This commit *only* adds annotations. A note on typing of __init__: mypy requires init functions with no parameters to document a return type of None to be considered fully typed. In the case when there are input parameters, None may be omitted. Since __init__ may never return any value, it is preferred to omit the return annotation whenever possible. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-25-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/commands.py: add type hint annotationsJohn Snow2020-10-102-23/+56
| | | | | | | | | | | | | | Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-23-jsnow@redhat.com> Message-Id: <20201009161558.107041-24-jsnow@redhat.com> [mypy.ini update squashed in] Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/commands.py: Don't re-bind to variable of different typeJohn Snow2020-10-101-3/+1Star
| | | | | | | | | | | | Mypy isn't a fan of rebinding a variable with a new data type. It's easy enough to avoid. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20201009161558.107041-22-jsnow@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
* qapi/events.py: Move comments into docstringsJohn Snow2020-10-101-1/+5
| | | | | | | | | | | Clarify them while we're here. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-21-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>