[PATCH RFC 20/32] python//qmp.py: assert sockfile is not None

John Snow posted 32 patches 5 years, 6 months ago
Maintainers: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Fam Zheng <fam@euphon.net>, Eduardo Habkost <ehabkost@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Markus Armbruster <armbru@redhat.com>, Max Reitz <mreitz@redhat.com>, Cleber Rosa <crosa@redhat.com>
[PATCH RFC 20/32] python//qmp.py: assert sockfile is not None
Posted by John Snow 5 years, 6 months ago
In truth, if you don't do this, you'll just get a TypeError
exception. Now, you'll get an AssertionError.

Is this tangibly better? No.
Does mypy complain less? Yes.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 python/qemu/lib/qmp.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py
index 5fb16f4b42..1aefc00c93 100644
--- a/python/qemu/lib/qmp.py
+++ b/python/qemu/lib/qmp.py
@@ -132,6 +132,7 @@ def __negotiate_capabilities(self):
         raise QMPCapabilitiesError
 
     def __json_read(self, only_event=False):
+        assert self.__sockfile is not None
         while True:
             data = self.__sockfile.readline()
             if not data:
-- 
2.21.1


Re: [PATCH RFC 20/32] python//qmp.py: assert sockfile is not None
Posted by Philippe Mathieu-Daudé 5 years, 5 months ago
On 5/14/20 7:53 AM, John Snow wrote:
> In truth, if you don't do this, you'll just get a TypeError
> exception. Now, you'll get an AssertionError.
> 
> Is this tangibly better? No.
> Does mypy complain less? Yes.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  python/qemu/lib/qmp.py | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py
> index 5fb16f4b42..1aefc00c93 100644
> --- a/python/qemu/lib/qmp.py
> +++ b/python/qemu/lib/qmp.py
> @@ -132,6 +132,7 @@ def __negotiate_capabilities(self):
>          raise QMPCapabilitiesError
>  
>      def __json_read(self, only_event=False):
> +        assert self.__sockfile is not None
>          while True:
>              data = self.__sockfile.readline()
>              if not data:
> 

Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Re: [PATCH RFC 20/32] python//qmp.py: assert sockfile is not None
Posted by Philippe Mathieu-Daudé 5 years, 5 months ago
On 5/26/20 6:03 PM, Philippe Mathieu-Daudé wrote:
> On 5/14/20 7:53 AM, John Snow wrote:
>> In truth, if you don't do this, you'll just get a TypeError
>> exception. Now, you'll get an AssertionError.
>>
>> Is this tangibly better? No.
>> Does mypy complain less? Yes.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>  python/qemu/lib/qmp.py | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py
>> index 5fb16f4b42..1aefc00c93 100644
>> --- a/python/qemu/lib/qmp.py
>> +++ b/python/qemu/lib/qmp.py
>> @@ -132,6 +132,7 @@ def __negotiate_capabilities(self):
>>          raise QMPCapabilitiesError
>>  
>>      def __json_read(self, only_event=False):
>> +        assert self.__sockfile is not None
>>          while True:
>>              data = self.__sockfile.readline()
>>              if not data:
>>
> 
> Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>

I meant:

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Re: [PATCH RFC 20/32] python//qmp.py: assert sockfile is not None
Posted by Philippe Mathieu-Daudé 5 years, 5 months ago
On 5/14/20 7:53 AM, John Snow wrote:
> In truth, if you don't do this, you'll just get a TypeError
> exception. Now, you'll get an AssertionError.
> 
> Is this tangibly better? No.
> Does mypy complain less? Yes.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  python/qemu/lib/qmp.py | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py
> index 5fb16f4b42..1aefc00c93 100644
> --- a/python/qemu/lib/qmp.py
> +++ b/python/qemu/lib/qmp.py
> @@ -132,6 +132,7 @@ def __negotiate_capabilities(self):
>          raise QMPCapabilitiesError
>  
>      def __json_read(self, only_event=False):
> +        assert self.__sockfile is not None
>          while True:
>              data = self.__sockfile.readline()
>              if not data:
> 

Thanks, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next