diff mbox series

[12/26] qapi/parser.py: add casts to pragma checks

Message ID 20200922223525.4085762-13-jsnow@redhat.com
State New
Headers show
Series qapi: static typing conversion, pt5 | expand

Commit Message

John Snow Sept. 22, 2020, 10:35 p.m. UTC
This kind of type checking at runtime is not something mypy can
introspect, so add a do-nothing cast to help mypy out.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/parser.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 75a693a9d7..9a1007f779 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -17,7 +17,7 @@ 
 import os
 import re
 from collections import OrderedDict
-from typing import Type, TypeVar
+from typing import List, Type, TypeVar, cast
 
 from .error import QAPIError, QAPISourceError, QAPISemError
 from .source import QAPISourceInfo
@@ -176,14 +176,14 @@  def _pragma(cls, name, value, info):
                 raise QAPISemError(
                     info,
                     "pragma returns-whitelist must be a list of strings")
-            info.pragma.returns_whitelist = value
+            info.pragma.returns_whitelist = cast(List[str], value)
         elif name == 'name-case-whitelist':
             if (not isinstance(value, list)
                     or any([not isinstance(elt, str) for elt in value])):
                 raise QAPISemError(
                     info,
                     "pragma name-case-whitelist must be a list of strings")
-            info.pragma.name_case_whitelist = value
+            info.pragma.name_case_whitelist = cast(List[str], value)
         else:
             raise QAPISemError(info, "unknown pragma '%s'" % name)