diff mbox series

[v6,26/36] qapi/gen.py: Fix edge-case of _is_user_module

Message ID 20201009161558.107041-27-jsnow@redhat.com
State Superseded
Headers show
Series qapi: static typing conversion, pt1 | expand

Commit Message

John Snow Oct. 9, 2020, 4:15 p.m. UTC
The edge case is that if the name is '', this expression returns a
string instead of a bool, which violates our declared type.

In practice, module names are not allowed to be the empty string, but
this constraint is not modeled for the type system.

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>
---
 scripts/qapi/gen.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Markus Armbruster Oct. 9, 2020, 5:26 p.m. UTC | #1
John Snow <jsnow@redhat.com> writes:

> The edge case is that if the name is '', this expression returns a

> string instead of a bool, which violates our declared type.

>

> In practice, module names are not allowed to be the empty string, but

> this constraint is not modeled for the type system.

>

> 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>

> ---

>  scripts/qapi/gen.py | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

>

> diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py

> index fff0c0acb6d..2c305c4f82c 100644

> --- a/scripts/qapi/gen.py

> +++ b/scripts/qapi/gen.py

> @@ -241,7 +241,7 @@ def __init__(self, prefix, what, user_blurb, builtin_blurb, pydoc):

>  

>      @staticmethod

>      def _is_user_module(name):

> -        return name and not name.startswith('./')

> +        return bool(name and not name.startswith('./'))


           return not (name is None or name.startswith('./')

Looks slightly clearer to me.

>  

>      @staticmethod

>      def _is_builtin_module(name):
diff mbox series

Patch

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index fff0c0acb6d..2c305c4f82c 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -241,7 +241,7 @@  def __init__(self, prefix, what, user_blurb, builtin_blurb, pydoc):
 
     @staticmethod
     def _is_user_module(name):
-        return name and not name.startswith('./')
+        return bool(name and not name.startswith('./'))
 
     @staticmethod
     def _is_builtin_module(name):