From ae8d6e6a025ae5d2dbfea0bf1dd5c705a139e515 Mon Sep 17 00:00:00 2001 From: pauladkisson Date: Tue, 24 Sep 2024 14:35:27 -0700 Subject: [PATCH] fixed python 3.9 isinstance bug --- src/roiextractors/imagingextractor.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/roiextractors/imagingextractor.py b/src/roiextractors/imagingextractor.py index f6a4f2f0..5aadf571 100644 --- a/src/roiextractors/imagingextractor.py +++ b/src/roiextractors/imagingextractor.py @@ -9,7 +9,7 @@ """ from abc import ABC, abstractmethod -from typing import Union, Optional, Tuple +from typing import Union, Optional, Tuple, get_args from copy import deepcopy import numpy as np @@ -244,8 +244,8 @@ def frame_slice(self, start_frame: Optional[int] = None, end_frame: Optional[int assert ( start_frame <= end_frame ), f"'start_frame' ({start_frame}) must be less than or equal to 'end_frame' ({end_frame})" - assert isinstance(start_frame, IntType), "'start_frame' must be an integer" - assert isinstance(end_frame, IntType), "'end_frame' must be an integer" + assert isinstance(start_frame, get_args(IntType)), "'start_frame' must be an integer" + assert isinstance(end_frame, get_args(IntType)), "'end_frame' must be an integer" return FrameSliceImagingExtractor(parent_imaging=self, start_frame=start_frame, end_frame=end_frame) @@ -306,8 +306,9 @@ def get_video(self, start_frame: Optional[int] = None, end_frame: Optional[int] assert ( start_frame <= end_frame ), f"'start_frame' ({start_frame}) must be less than or equal to 'end_frame' ({end_frame})" - assert isinstance(start_frame, int), "'start_frame' must be an integer" - assert isinstance(end_frame, int), "'end_frame' must be an integer" + # python 3.9 doesn't support get_instance on a Union of types, so we use get_args + assert isinstance(start_frame, get_args(IntType)), "'start_frame' must be an integer" + assert isinstance(end_frame, get_args(IntType)), "'end_frame' must be an integer" start_frame_shifted = start_frame + self._start_frame end_frame_shifted = end_frame + self._start_frame