diff --git a/mne_bids/path.py b/mne_bids/path.py index c76fb2a2a..63d6d1259 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -1473,7 +1473,7 @@ def search_folder_for_text( def _check_max_depth(max_depth): """Check that max depth is a proper input.""" msg = "`max_depth` must be a positive integer or None" - if not isinstance(max_depth, (int, type(None))): + if not isinstance(max_depth, int | type(None)): raise ValueError(msg) if max_depth is None: max_depth = float("inf") @@ -2217,7 +2217,7 @@ def _infer_datatype(*, root, sub, ses): def _path_to_str(var): """Make sure var is a string or Path, return string representation.""" - if not isinstance(var, (Path, str)): + if not isinstance(var, Path | str): raise ValueError( f"All path parameters must be either strings or " f"pathlib.Path objects. Found type {type(var)}." diff --git a/mne_bids/tsv_handler.py b/mne_bids/tsv_handler.py index 73bc228bc..532caa370 100644 --- a/mne_bids/tsv_handler.py +++ b/mne_bids/tsv_handler.py @@ -153,7 +153,7 @@ def _from_tsv(fname, dtypes=None): data_dict = OrderedDict() if dtypes is None: dtypes = [str] * info.shape[1] - if not isinstance(dtypes, (list, tuple)): + if not isinstance(dtypes, list | tuple): dtypes = [dtypes] * info.shape[1] if not len(dtypes) == info.shape[1]: raise ValueError( diff --git a/mne_bids/utils.py b/mne_bids/utils.py index 0bc80c2c1..fe3ad5738 100644 --- a/mne_bids/utils.py +++ b/mne_bids/utils.py @@ -210,7 +210,7 @@ def _age_on_date(bday, exp_date): def _check_types(variables): """Make sure all vars are str or None.""" for var in variables: - if not isinstance(var, (str, type(None))): + if not isinstance(var, str | type(None)): raise ValueError( f"You supplied a value ({var}) of type " f"{type(var)}, where a string or None was " @@ -271,7 +271,7 @@ def _get_mrk_meas_date(mrk): """Find the measurement date from a KIT marker file.""" info = get_kit_info(mrk, False)[0] meas_date = info.get("meas_date", None) - if isinstance(meas_date, (tuple, list, np.ndarray)): + if isinstance(meas_date, tuple | list | np.ndarray): meas_date = meas_date[0] if isinstance(meas_date, datetime): meas_datetime = meas_date diff --git a/mne_bids/write.py b/mne_bids/write.py index c7bd1896d..16b817be8 100644 --- a/mne_bids/write.py +++ b/mne_bids/write.py @@ -90,7 +90,7 @@ def _is_numeric(n): - return isinstance(n, (np.integer, np.floating, int, float)) + return isinstance(n, np.integer | np.floating | int | float) def _channels_tsv(raw, fname, overwrite=False): @@ -459,7 +459,7 @@ def _participants_tsv(raw, subject_id, fname, overwrite=False): if isinstance(age, tuple): # can be removed once MNE >= 1.8 is required age = date(*age) meas_date = raw.info.get("meas_date", None) - if isinstance(meas_date, (tuple, list, np.ndarray)): + if isinstance(meas_date, tuple | list | np.ndarray): meas_date = meas_date[0] if meas_date is not None and age is not None: @@ -2267,7 +2267,7 @@ def _get_t1w_mgh(fs_subject, fs_subjects_dir): def _get_landmarks(landmarks, image_nii, kind=""): import nibabel as nib - if isinstance(landmarks, (str, Path)): + if isinstance(landmarks, str | Path): landmarks, coord_frame = read_fiducials(landmarks) landmarks = np.array( [landmark["r"] for landmark in landmarks], dtype=float