John Snow and Markus Armbruster
e2bbc4eaa7
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
12893a8ea7
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 >
2021-02-08 14:15:58 +01:00
Markus Armbruster
f3a705928a
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
98967c248c
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
a253b3eb9a
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
ad1218086e
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
3cc01c546b
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
ec9697ab3f
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 >
2021-02-08 14:15:58 +01:00
John Snow and Markus Armbruster
b4c0aa59af
qapi/visit.py: add type hint annotations
...
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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
2cc1eefb84
qapi/visit.py: remove unused parameters from gen_visit_object
...
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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
554df4f33f
qapi/visit.py: assert tag_member contains a QAPISchemaEnumType
...
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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
dec44d3d65
qapi/types.py: remove one-letter variables
...
"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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
cd073c8fb0
qapi/types.py: add type hint annotations
...
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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
9abddb5be4
qapi/gen.py: delint with pylint
...
'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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
cc6263c44b
qapi/gen.py: update write() to be more idiomatic
...
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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
0cbd5b0516
qapi/gen.py: Remove unused parameter
...
_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 >
2020-10-10 11:37:49 +02:00
John Snow and Markus Armbruster
17d40c3957
qapi/gen.py: add type hint annotations
...
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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
3ae1c84851
qapi/gen: Make _is_user_module() return bool
...
_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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
96670e89ec
qapi/source.py: delint with pylint
...
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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
f5d4361cda
qapi/source.py: add type hint annotations
...
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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
7304721f9e
qapi/commands.py: add type hint annotations
...
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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
ab2d8a75b6
qapi/commands.py: Don't re-bind to variable of different type
...
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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
1a503761e4
qapi/events.py: Move comments into docstrings
...
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 >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
d1b21b393e
qapi/events.py: add type hint annotations
...
Annotations do not change runtime behavior.
This commit *only* adds annotations.
Note: __init__ does not need its return type annotated, as it is special.
https://mypy.readthedocs.io/en/stable/class_basics.html#annotating-init-methods
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-20-jsnow@redhat.com >
Reviewed-by: Markus Armbruster <armbru@redhat.com >
Signed-off-by: Markus Armbruster <armbru@redhat.com >
2020-10-10 11:37:48 +02:00
John Snow and Markus Armbruster
7e09d7882d
qapi: establish mypy type-checking baseline
...
Fix a minor typing issue, and then establish a mypy type-checking
baseline.
Like pylint, this should be run from the folder above:
> mypy --config-file=qapi/mypy.ini qapi/
This is designed and tested for mypy 0.770 or greater.
Signed-off-by: John Snow <jsnow@redhat.com >
Tested-by: Eduardo Habkost <ehabkost@redhat.com >
Reviewed-by: Cleber Rosa <crosa@redhat.com >
Tested-by: Cleber Rosa <crosa@redhat.com >
Message-Id: <20201009161558.107041-19-jsnow@redhat.com >
Reviewed-by: Markus Armbruster <armbru@redhat.com >
Signed-off-by: Markus Armbruster <armbru@redhat.com >
2020-10-10 11:37:48 +02:00