[gobject-introspection: 2/3] Add basic mypy support
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection: 2/3] Add basic mypy support
- Date: Sun, 8 Nov 2020 14:58:09 +0000 (UTC)
commit 1b3237ba383ba644628defcfde443e9a4e5af69c
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Nov 7 11:00:30 2020 +0100
Add basic mypy support
Silence some errors, run mypy in CI
Adding annotations to functions/classes will make mypy check them.
.gitignore | 3 +++
.gitlab-ci.yml | 3 ++-
.gitlab-ci/test-msys2-meson.sh | 3 ++-
giscanner/__init__.py | 2 +-
giscanner/annotationparser.py | 3 ++-
giscanner/utils.py | 4 ++--
mypy.ini | 3 +++
7 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 2f1be7230..1e9e54eb4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -155,3 +155,6 @@ htmlcov*
#emacs
.dir-locals.el
+
+
+.mypy_cache
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e9e79b979..2d79aa1da 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -56,8 +56,9 @@ fedora-x86_64-meson:
- cd ..
- mkdir -p public
- mv _build/docs/reference/html/ public/girepository/
- - python3 -m pip install --user flake8
+ - python3 -m pip install --user flake8 mypy
- python3 -m flake8 --count
+ - python3 -m mypy .
except:
- tags
artifacts:
diff --git a/.gitlab-ci/test-msys2-meson.sh b/.gitlab-ci/test-msys2-meson.sh
index 9f145e5b5..81a82437d 100644
--- a/.gitlab-ci/test-msys2-meson.sh
+++ b/.gitlab-ci/test-msys2-meson.sh
@@ -31,7 +31,7 @@ pacman --noconfirm -S --needed \
export CCACHE_BASEDIR="${CI_PROJECT_DIR}"
export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
-pip3 install --upgrade --user meson==0.50.1 flake8
+pip3 install --upgrade --user meson==0.50.1 flake8 mypy
export PATH="$HOME/.local/bin:$PATH"
export CFLAGS="-Werror"
@@ -43,3 +43,4 @@ meson test --print-errorlogs --suite=gobject-introspection --no-suite=glib
cd ..
python3 -m flake8 --count
+python3 -m mypy .
\ No newline at end of file
diff --git a/giscanner/__init__.py b/giscanner/__init__.py
index 79c537e8f..7c2f365ab 100644
--- a/giscanner/__init__.py
+++ b/giscanner/__init__.py
@@ -20,7 +20,7 @@
import os
builddir = os.environ.get('UNINSTALLED_INTROSPECTION_BUILDDIR')
if builddir is not None:
- __path__.append(os.path.join(builddir, 'giscanner'))
+ __path__.append(os.path.join(builddir, 'giscanner')) # type: ignore # mypy issue #1422
try:
from ._version import __version__
except ImportError:
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index f8257206f..267542f95 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -110,6 +110,7 @@ import os
import re
import operator
+from typing import Tuple
from operator import ne, gt, lt
from collections import namedtuple, Counter, OrderedDict
@@ -575,7 +576,7 @@ class GtkDocAnnotatable(object):
#: A :class:`tuple` of annotation name constants that are valid for this object. Annotation
#: names not in this :class:`tuple` will be reported as *unknown* by :func:`validate`. The
#: :attr:`valid_annotations` class attribute should be overridden by subclasses.
- valid_annotations = ()
+ valid_annotations = () # type: Tuple[str,...]
def __init__(self, position=None):
#: A :class:`giscanner.message.Position` instance specifying the location of the
diff --git a/giscanner/utils.py b/giscanner/utils.py
index d9938fc7e..9007db133 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -346,5 +346,5 @@ def get_msvcr_overwrite():
import distutils.cygwinccompiler
-orig_get_msvcr = distutils.cygwinccompiler.get_msvcr
-distutils.cygwinccompiler.get_msvcr = get_msvcr_overwrite
+orig_get_msvcr = distutils.cygwinccompiler.get_msvcr # type: ignore
+distutils.cygwinccompiler.get_msvcr = get_msvcr_overwrite # type: ignore
diff --git a/mypy.ini b/mypy.ini
new file mode 100644
index 000000000..e69a623d7
--- /dev/null
+++ b/mypy.ini
@@ -0,0 +1,3 @@
+[mypy]
+ignore_missing_imports = True
+python_version = 3.5
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]