Skip to content

Commit

Permalink
Resolve type errors; refactor non-pythonic code
Browse files Browse the repository at this point in the history
Signed-off-by: Asadullah Shaikh <[email protected]>
  • Loading branch information
pantheraleo-7 authored and davidplowman committed Dec 18, 2024
1 parent 31e381f commit acba763
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ def __init__(self, camera_num=0, verbose_console=None, tuning=None, allocator=No
_log.debug(f"{self.camera_manager}")
# We deliberately make raw streams with no size so that it will be filled in
# later once the main stream size has been set.
self.preview_configuration = self.create_preview_configuration()
self.preview_configuration.enable_raw() # causes the size to be reset to None
self.still_configuration = self.create_still_configuration()
self.still_configuration.enable_raw() # ditto
self.video_configuration = self.create_video_configuration()
self.video_configuration.enable_raw() # ditto
self.preview_configuration_ = CameraConfiguration(self.create_preview_configuration(), self)
self.preview_configuration_.enable_raw() # causes the size to be reset to None
self.still_configuration_ = CameraConfiguration(self.create_still_configuration(), self)
self.still_configuration_.enable_raw() # ditto
self.video_configuration_ = CameraConfiguration(self.create_video_configuration(), self)
self.video_configuration_.enable_raw() # ditto
except Exception:
_log.error("Camera __init__ sequence did not complete.")
raise RuntimeError("Camera __init__ sequence did not complete.")
Expand Down Expand Up @@ -425,12 +425,10 @@ def _grab_camera(self, idx):
elif isinstance(idx, int):
return self.camera_manager.cameras[idx]

def _initialize_camera(self) -> bool:
def _initialize_camera(self) -> None:
"""Initialize camera
:raises RuntimeError: Failure to initialise camera
:return: True if success
:rtype: bool
"""
if not self.camera_manager.cameras:
_log.error("Camera(s) not found (Do not forget to disable legacy camera with raspi-config).")
Expand Down Expand Up @@ -458,7 +456,6 @@ def _initialize_camera(self) -> bool:
self.sensor_format = self._native_mode['format']

_log.info('Initialization successful.')
return True

def __identify_camera(self):
for idx, address in enumerate(self.camera_manager.cameras):
Expand All @@ -471,7 +468,9 @@ def _open_camera(self) -> None:
:raises RuntimeError: Failed to setup camera
"""
if not self._initialize_camera():
try:
self._initialize_camera()
except RuntimeError:
raise RuntimeError("Failed to initialize camera")

# This now throws an error if it can't open the camera.
Expand Down Expand Up @@ -628,12 +627,12 @@ def close(self) -> None:
self.streams = None
self.stream_map = None
self.camera = None
self.camera_ctrl_info = None
self.camera_ctrl_info = {}
self.camera_config = None
self.libcamera_config = None
self.preview_configuration_ = None
self.still_configuration_ = None
self.video_configuration_ = None
self.preview_configuration = {}
self.still_configuration = {}
self.video_configuration = {}
self.notifymeread.close()
os.close(self.notifyme_w)
# Clean up the allocator
Expand Down

0 comments on commit acba763

Please sign in to comment.