Message ID | 20201009175123.249009-1-jsnow@redhat.com |
---|---|
Headers | show |
Series | python/qemu: strictly typed mypy conversion, pt3 | expand |
On 10/9/20 1:51 PM, John Snow wrote: > This is actually quite short; it's already fully typed. Attached are two > fixes for settimeout and error handling. There are actually more fixes > that need to be made here, because use of readline() in non-blocking > mode is actually undefined behavior, so a more thorough re-work of the > error classes used by this library must be put on hold pending a more > aggressive re-write. > > That's a problem for later, so for now, call the initial conversion to > the statically typed subset of python done so we can move on to adding > the regression tests that will maintain this baseline for us. > > John Snow (3): > python: add mypy config > python/qemu/qmp.py: re-raise OSError when encountered > python/qemu/qmp.py: Fix settimeout operation > > python/mypy.ini | 4 ++++ > python/qemu/qmp.py | 30 +++++++++++++++++++++--------- > 2 files changed, 25 insertions(+), 9 deletions(-) > create mode 100644 python/mypy.ini > Based on: https://gitlab.com/jsnow/qemu/-/tree/python
On 10/9/20 7:51 PM, John Snow wrote: > Nested if conditions don't change when the exception block fires; we > need to explicitly re-raise the error if we didn't intend to capture and > suppress it. > > Signed-off-by: John Snow <jsnow@redhat.com> > --- > python/qemu/qmp.py | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
On 10/9/20 7:51 PM, John Snow wrote: > We enabled callers to interface directly with settimeout, but this > reacts poorly with blocking/nonblocking operation; as they are using the > same internal mechanism. > > 1. Whenever we change the blocking mechanism temporarily, always set it > back to what it was afterwards. > > 2. Disallow callers from setting a timeout of "0", which means > Non-blocking mode. This is going to create more weird problems than > anybody wants, so just forbid it. > > I opt not to coerce '0' to 'None' to maintain the principal of least > surprise in mirroring the semantics of Python's interface. > > Signed-off-by: John Snow <jsnow@redhat.com> > --- > python/qemu/qmp.py | 23 +++++++++++++++++------ > 1 file changed, 17 insertions(+), 6 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
On 10/9/20 1:51 PM, John Snow wrote: > This is actually quite short; it's already fully typed. Attached are two > fixes for settimeout and error handling. There are actually more fixes > that need to be made here, because use of readline() in non-blocking > mode is actually undefined behavior, so a more thorough re-work of the > error classes used by this library must be put on hold pending a more > aggressive re-write. > > That's a problem for later, so for now, call the initial conversion to > the statically typed subset of python done so we can move on to adding > the regression tests that will maintain this baseline for us. > > John Snow (3): > python: add mypy config > python/qemu/qmp.py: re-raise OSError when encountered > python/qemu/qmp.py: Fix settimeout operation > > python/mypy.ini | 4 ++++ > python/qemu/qmp.py | 30 +++++++++++++++++++++--------- > 2 files changed, 25 insertions(+), 9 deletions(-) > create mode 100644 python/mypy.ini > Thanks -- tentatively staging to my Python branch. I intend to send a PR on Friday, so if there's more feedback, there's plenty of time. https://gitlab.com/jsnow/qemu.git python https://gitlab.com/jsnow/qemu/-/commits/python