Skip to content

Commit

Permalink
Fix typehint problem with ndarrays (#1631)
Browse files Browse the repository at this point in the history
mypy was inferring the wrong type for ndarrays in photonCameraSim.py.
This fixes the problem by adding typehints using numpy.typing.NDArray.
  • Loading branch information
crschardt authored Dec 9, 2024
1 parent 782929b commit 6a8d638
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions photon-lib/py/photonlibpy/simulation/simCameraProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import cv2 as cv
import numpy as np
import numpy.typing as npt
from wpimath.geometry import Rotation2d, Rotation3d, Translation3d
from wpimath.units import hertz, seconds

Expand Down Expand Up @@ -31,8 +32,8 @@ def __init__(self):
"""Default constructor which is the same as {@link #PERFECT_90DEG}"""
self.resWidth: int = -1
self.resHeight: int = -1
self.camIntrinsics: np.ndarray = np.zeros((3, 3)) # [3,3]
self.distCoeffs: np.ndarray = np.zeros((8, 1)) # [8,1]
self.camIntrinsics: npt.NDArray[np.floating] = np.zeros((3, 3)) # [3,3]
self.distCoeffs: npt.NDArray[np.floating] = np.zeros((8, 1)) # [8,1]
self.avgErrorPx: float = 0.0
self.errorStdDevPx: float = 0.0
self.frameSpeed: seconds = 0.0
Expand Down Expand Up @@ -172,10 +173,10 @@ def getResArea(self) -> int:
def getAspectRatio(self) -> float:
return 1.0 * self.resWidth / self.resHeight

def getIntrinsics(self) -> np.ndarray:
def getIntrinsics(self) -> npt.NDArray[np.floating]:
return self.camIntrinsics

def getDistCoeffs(self) -> np.ndarray:
def getDistCoeffs(self) -> npt.NDArray[np.floating]:
return self.distCoeffs

def getFPS(self) -> hertz:
Expand Down

0 comments on commit 6a8d638

Please sign in to comment.