From 3e5eece5e1e5d77d2c5ea355bc8637549388b9d5 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 7 Nov 2020 10:44:16 +0100 Subject: Require Python 3.5 3.4 is long EOL and we don't test it, so don't pretend that we support it. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 3bbcf8de..546ab885 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,7 @@ pymod = import('python') python = pymod.find_installation(get_option('python')) python_version = python.language_version() -python_version_req = '>=3.4' +python_version_req = '>=3.5' if not python_version.version_compare(python_version_req) error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version)) endif -- cgit v1.2.1 From 1b3237ba383ba644628defcfde443e9a4e5af69c Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sat, 7 Nov 2020 11:00:30 +0100 Subject: 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(-) create mode 100644 mypy.ini diff --git a/.gitignore b/.gitignore index 2f1be723..1e9e54eb 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 e9e79b97..2d79aa1d 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 9f145e5b..81a82437 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 79c537e8..7c2f365a 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 f8257206..267542f9 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 d9938fc7..9007db13 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 00000000..e69a623d --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +ignore_missing_imports = True +python_version = 3.5 \ No newline at end of file -- cgit v1.2.1