Annotate just enough to make mypy happy.
There's a *lot* of legacy code to add type annotations for, but this
is enough to make mypy happy (it can infer a lot).
Test: mypy --ignore-missing-imports ndk
Bug: None
Change-Id: I11b86751ed8cba237dabeabba7c23966f5c08fc4
diff --git a/ndk/builds.py b/ndk/builds.py
index 51bdf4f..873a5fb 100644
--- a/ndk/builds.py
+++ b/ndk/builds.py
@@ -24,6 +24,7 @@
import shutil
import stat
import subprocess
+from typing import Iterable, Optional, Set
import ndk.abis
import ndk.ext.shutil
@@ -56,9 +57,9 @@
class Module(object):
- name = None
- path = None
- deps = set()
+ name: Optional[str] = None
+ path: Optional[str] = None
+ deps: Set[str] = set()
# Used to exclude a module from the build. If explicitly named it will
# still be built, but it is not included by default.
@@ -267,7 +268,7 @@
class InvokeExternalBuildModule(Module):
- script = None
+ script: Optional[str] = None
arch_specific = False
def build(self):
@@ -308,7 +309,7 @@
class MultiFileModule(Module):
- files = []
+ files: Iterable[str] = []
def build(self):
pass
@@ -321,8 +322,8 @@
class ScriptShortcutModule(Module):
- script = None
- windows_ext = None
+ script: Optional[str] = None
+ windows_ext: Optional[str] = None
# These are all trivial shell scripts that we generated. No notice needed.
no_notice = True
diff --git a/ndk/checkbuild.py b/ndk/checkbuild.py
index 49e5798..02d696c 100755
--- a/ndk/checkbuild.py
+++ b/ndk/checkbuild.py
@@ -49,6 +49,7 @@
import tempfile
import textwrap
import traceback
+from typing import Dict
from build.lib import build_support
import ndk.abis
@@ -926,7 +927,7 @@
# ABI_ANDROID_API in crtbrand is an integer. We start counting the
# codenamed releases from 9000 and increment for each additional release.
# This is filled by get_apis.
- codename_api_map = {}
+ codename_api_map: Dict[str, int] = {}
# Shared with the sysroot, though the sysroot NOTICE actually includes a
# lot more licenses. Platforms and Sysroot are essentially a single
diff --git a/ndk/test/scanner.py b/ndk/test/scanner.py
index 6186c0b..f7ddb67 100644
--- a/ndk/test/scanner.py
+++ b/ndk/test/scanner.py
@@ -16,6 +16,7 @@
from __future__ import absolute_import
import os
+from typing import List
import ndk.test.spec
import ndk.test.types
@@ -105,7 +106,7 @@
class LibcxxTestScanner(TestScanner):
- ALL_TESTS = []
+ ALL_TESTS: List[str] = []
def __init__(self, ndk_path):
self.ndk_path = ndk_path
diff --git a/ndk/test_deps.py b/ndk/test_deps.py
index daa73f4..aed826b 100644
--- a/ndk/test_deps.py
+++ b/ndk/test_deps.py
@@ -15,6 +15,7 @@
# limitations under the License.
#
"""Test for ndk.deps."""
+from typing import Set
import unittest
from ndk.deps import CyclicDependencyError
@@ -36,20 +37,20 @@
# A module with no dependents or dependencies. Should be immediately buildable.
class Isolated(object):
name = 'isolated'
- deps = set()
+ deps: Set[str] = set()
# A module that is not present in the build graph.
class Unknown(object):
name = 'unknown'
- deps = set()
+ deps: Set[str] = set()
# A simple chain of two modules. The first should be immediately buildable, and
# the second should become buildable after it completes.
class SimpleA(object):
name = 'simpleA'
- deps = set()
+ deps: Set[str] = set()
class SimpleB(object):
@@ -60,7 +61,7 @@
# Slightly more complex module graph.
class ComplexA(object):
name = 'complexA'
- deps = set()
+ deps: Set[str] = set()
class ComplexB(object):
diff --git a/ndk/win32.py b/ndk/win32.py
index 6f8d1c9..9510f04 100644
--- a/ndk/win32.py
+++ b/ndk/win32.py
@@ -60,7 +60,9 @@
]
-class UseLastErrorWinDLL(ctypes.WinDLL):
+# mypy needs to ignore this line because this only typechecks successfully for
+# Windows.
+class UseLastErrorWinDLL(ctypes.WinDLL): # type: ignore
def __init__(self, name, mode=ctypes.DEFAULT_MODE, handle=None):
super(UseLastErrorWinDLL, self).__init__(name, mode, handle, use_last_error=True)