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>
This commit is contained in:
John Snow 2020-10-09 12:15:40 -04:00 committed by Markus Armbruster
parent e6a34cd7a4
commit 7e09d7882d
2 changed files with 62 additions and 1 deletions

60
scripts/qapi/mypy.ini Normal file
View File

@ -0,0 +1,60 @@
[mypy]
strict = True
strict_optional = False
disallow_untyped_calls = False
python_version = 3.6
[mypy-qapi.commands]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.error]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.events]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.expr]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.gen]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.introspect]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.parser]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.schema]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.source]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.types]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
[mypy-qapi.visit]
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False

View File

@ -17,6 +17,7 @@
from collections import OrderedDict
import os
import re
from typing import Optional
from .common import POINTER_SUFFIX, c_name
from .error import QAPIError, QAPISemError
@ -25,7 +26,7 @@ from .parser import QAPISchemaParser
class QAPISchemaEntity:
meta = None
meta: Optional[str] = None
def __init__(self, name, info, doc, ifcond=None, features=None):
assert name is None or isinstance(name, str)