From 11b9cb9fb50645cf9ff9e83203ccd157afd90d2c Mon Sep 17 00:00:00 2001 From: Dylan Herman Date: Mon, 2 May 2022 18:48:04 -0500 Subject: [PATCH] enable numpy mypy typing (#24387) * enable numpy mypy typing * remove --warn-return-any * merge conflict and syntax * merge conflict * merge conflict * add type to img var old-commit-hash: 603942ffe0f5f0dba9f14f1293306bc0482e0032 --- .pre-commit-config.yaml | 5 ++--- common/transformations/orientation.py | 3 ++- common/window.py | 4 ++-- mypy.ini | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10762162a7..912ba1344e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,12 +20,11 @@ repos: hooks: - id: mypy exclude: '^(pyextra/)|(cereal/)|(rednose/)|(panda/)|(laika/)|(opendbc/)|(laika_repo/)|(rednose_repo/)/' - additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites', - 'types-pycurl', 'types-certifi', 'lxml'] + additional_dependencies: ['lxml', 'numpy', 'types-atomicwrites', 'types-pycurl', 'types-requests', 'types-certifi'] args: - - --warn-unused-ignores - --warn-redundant-casts - --warn-unreachable + - --warn-unused-ignores #- --html-report=/home/batman/openpilot - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 diff --git a/common/transformations/orientation.py b/common/transformations/orientation.py index 415e247ab2..134442b624 100644 --- a/common/transformations/orientation.py +++ b/common/transformations/orientation.py @@ -1,5 +1,6 @@ # pylint: skip-file import numpy as np +from typing import Callable from common.transformations.transformations import (ecef_euler_from_ned_single, euler2quat_single, @@ -11,7 +12,7 @@ from common.transformations.transformations import (ecef_euler_from_ned_single, rot2quat_single) -def numpy_wrap(function, input_shape, output_shape): +def numpy_wrap(function, input_shape, output_shape) -> Callable[..., np.ndarray]: """Wrap a function to take either an input or list of inputs and return the correct shape""" def f(*inps): *args, inp = inps diff --git a/common/window.py b/common/window.py index ce1eecb881..613b3b201b 100644 --- a/common/window.py +++ b/common/window.py @@ -2,7 +2,7 @@ import sys import pygame # pylint: disable=import-error import cv2 # pylint: disable=import-error -class Window(): +class Window: def __init__(self, w, h, caption="window", double=False, halve=False): self.w = w self.h = h @@ -54,7 +54,7 @@ class Window(): if __name__ == "__main__": import numpy as np win = Window(200, 200, double=True) - img = np.zeros((200, 200, 3), np.uint8) + img: np.ndarray = np.zeros((200, 200, 3), np.uint8) while 1: print("draw") img += 1 diff --git a/mypy.ini b/mypy.ini index 66b82bd5df..e2da60f926 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,4 +1,4 @@ [mypy] python_version = 3.8 ignore_missing_imports = True - +plugins = numpy.typing.mypy_plugin