From 8e50a90fb2b5875a9889555c8e23fc9107b212f0 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 21 Mar 2023 15:04:49 +0000 Subject: [PATCH] Explicitly mark arguments as optional mypy now considers implicitly Optional arguments to be errors - I have made them now explicitly Optional, which passes. --- openflexure_microscope/camera/pi.py | 8 ++++---- openflexure_microscope/config.py | 4 +++- openflexure_microscope/microscope.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index 4f892734..6052363b 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -30,7 +30,7 @@ import logging import time # Type hinting -from typing import BinaryIO, Tuple, Union +from typing import BinaryIO, Tuple, Union, Optional import numpy as np @@ -307,7 +307,7 @@ class PiCameraStreamer(BaseCamera): self.picamera.zoom = new_fov def start_preview( - self, fullscreen: bool = True, window: Tuple[int, int, int, int] = None + self, fullscreen: bool = True, window: Optional[Tuple[int, int, int, int]] = None ): """Start the on board GPU camera preview.""" with self.lock(timeout=1): @@ -462,9 +462,9 @@ class PiCameraStreamer(BaseCamera): output: Union[str, BinaryIO], fmt: str = "jpeg", use_video_port: bool = False, - resize: Tuple[int, int] = None, + resize: Optional[Tuple[int, int]] = None, bayer: bool = True, - thumbnail: Tuple[int, int, int] = None, + thumbnail: Optional[Tuple[int, int, int]] = None, ): """ Capture a still image to a StreamObject. diff --git a/openflexure_microscope/config.py b/openflexure_microscope/config.py index f7b9552f..8ceed138 100644 --- a/openflexure_microscope/config.py +++ b/openflexure_microscope/config.py @@ -3,6 +3,8 @@ import json import logging import os import shutil +from typing import Optional + from .json import JSONEncoder from .paths import CONFIGURATION_FILE_PATH, SETTINGS_FILE_PATH @@ -17,7 +19,7 @@ class OpenflexureSettingsFile: expand (bool): Expand paths to valid auxillary config files. """ - def __init__(self, path: str, defaults: dict = None): + def __init__(self, path: str, defaults: Optional[dict] = None): defaults = defaults or {} # Set arguments diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index f97d3dc6..83f8d591 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -370,7 +370,7 @@ class Microscope: folder: str = "", temporary: bool = False, use_video_port: bool = False, - resize: Tuple[int, int] = None, + resize: Optional[Tuple[int, int]] = None, bayer: bool = True, fmt: str = "jpeg", annotations: Optional[Dict[str, str]] = None,