Skip to content

Commit

Permalink
Manually apply ruff/flake8-implicit-str-concat rule ISC001
Browse files Browse the repository at this point in the history
	ISC001 Implicitly concatenated string literals on one line

This rule is currently disabled because it conflicts with the formatter:
	astral-sh/ruff#8272
  • Loading branch information
DimitriPapadopoulos committed May 5, 2024
1 parent 797ef4c commit 070ab62
Show file tree
Hide file tree
Showing 46 changed files with 71 additions and 85 deletions.
2 changes: 1 addition & 1 deletion mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3350,7 +3350,7 @@ def _force_update_info(info_base, info_target):
all_infos = np.hstack([info_base, info_target])
for ii in all_infos:
if not isinstance(ii, Info):
raise ValueError("Inputs must be of type Info. " f"Found type {type(ii)}")
raise ValueError(f"Inputs must be of type Info. Found type {type(ii)}")
for key, val in info_base.items():
if key in exclude_keys:
continue
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def plot_projs_topomap(
_projs.remove(_proj)
if len(_projs) == 0:
raise ValueError(
"Nothing to plot (no projectors for channel " f"type {ch_type})."
f"Nothing to plot (no projectors for channel type {ch_type})."
)
# now we have non-empty _projs list with correct channel type(s)
from ..viz.topomap import plot_projs_topomap
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_constants(tmp_path):
fname = "fiff.zip"
dest = tmp_path / fname
pooch.retrieve(
url="https://codeload.github.com/" f"{REPO}/fiff-constants/zip/{COMMIT}",
url=f"https://codeload.github.com/{REPO}/fiff-constants/zip/{COMMIT}",
path=tmp_path,
fname=fname,
known_hash=None,
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _get_split_size(split_size):
if isinstance(split_size, str):
exp = dict(MB=20, GB=30).get(split_size[-2:], None)
if exp is None:
raise ValueError("split_size has to end with either" '"MB" or "GB"')
raise ValueError('split_size has to end with either "MB" or "GB"')
split_size = int(float(split_size[:-2]) * 2**exp)

if split_size > 2147483648:
Expand Down
2 changes: 1 addition & 1 deletion mne/bem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def get_fitting_dig(info, dig_kinds="auto", exclude_frontal=True, verbose=None):
_validate_type(info, "info")
if info["dig"] is None:
raise RuntimeError(
"Cannot fit headshape without digitization " ', info["dig"] is None'
'Cannot fit headshape without digitization, info["dig"] is None'
)
if isinstance(dig_kinds, str):
if dig_kinds == "auto":
Expand Down
10 changes: 4 additions & 6 deletions mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ def combine_channels(
# Instantiate channel info and data
new_ch_names, new_ch_types, new_data = [], [], []
if not isinstance(keep_stim, bool):
raise TypeError('"keep_stim" must be of type bool, not ' f"{type(keep_stim)}.")
raise TypeError(f'"keep_stim" must be of type bool, not {type(keep_stim)}.')
if keep_stim:
stim_ch_idx = list(pick_types(inst.info, meg=False, stim=True))
if stim_ch_idx:
Expand All @@ -1915,7 +1915,7 @@ def combine_channels(
# Get indices of bad channels
ch_idx_bad = []
if not isinstance(drop_bad, bool):
raise TypeError('"drop_bad" must be of type bool, not ' f"{type(drop_bad)}.")
raise TypeError(f'"drop_bad" must be of type bool, not {type(drop_bad)}.')
if drop_bad and inst.info["bads"]:
ch_idx_bad = pick_channels(ch_names, inst.info["bads"])

Expand All @@ -1937,7 +1937,7 @@ def combine_channels(
this_picks = [idx for idx in this_picks if idx not in ch_idx_bad]
if these_bads:
logger.info(
"Dropped the following channels in group " f"{this_group}: {these_bads}"
f"Dropped the following channels in group {this_group}: {these_bads}"
)
# Check if combining less than 2 channel
if len(set(this_picks)) < 2:
Expand Down Expand Up @@ -2130,9 +2130,7 @@ def read_vectorview_selection(name, fname=None, info=None, verbose=None):
# get the name of the selection in the file
pos = line.find(":")
if pos < 0:
logger.info(
'":" delimiter not found in selections file, ' "skipping line"
)
logger.info('":" delimiter not found in selections file, skipping line')
continue
sel_name_file = line[:pos]
# search for substring match with name provided
Expand Down
4 changes: 2 additions & 2 deletions mne/channels/tests/test_montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ def test_montage_add_fiducials():

# check that adding MNI fiducials fails because we're in MRI
with pytest.raises(
RuntimeError, match="Montage should be in the " '"mni_tal" coordinate frame'
RuntimeError, match='Montage should be in the "mni_tal" coordinate frame'
):
montage.add_mni_fiducials(subjects_dir=subjects_dir)

Expand All @@ -1991,7 +1991,7 @@ def test_montage_add_fiducials():
# which is the FreeSurfer RAS
montage = make_dig_montage(ch_pos=test_ch_pos, coord_frame="mni_tal")
with pytest.raises(
RuntimeError, match="Montage should be in the " '"mri" coordinate frame'
RuntimeError, match='Montage should be in the "mri" coordinate frame'
):
montage.add_estimated_fiducials(subject=subject, subjects_dir=subjects_dir)

Expand Down
4 changes: 2 additions & 2 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ def _check_pyqtgraph(request):
f_name = request.function.__name__
if lower_2_0 and m_name in pre_2_0_skip_modules:
pytest.skip(
f'Test-Module "{m_name}" was skipped for' f" mne-qt-browser < 0.2.0"
f'Test-Module "{m_name}" was skipped for mne-qt-browser < 0.2.0'
)
elif lower_2_0 and f_name in pre_2_0_skip_funcs:
pytest.skip(f'Test "{f_name}" was skipped for ' f"mne-qt-browser < 0.2.0")
pytest.skip(f'Test "{f_name}" was skipped for mne-qt-browser < 0.2.0')
except Exception:
pytest.skip("Requires mne_qt_browser")
else:
Expand Down
6 changes: 2 additions & 4 deletions mne/decoding/csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ def __init__(
if transform_into == "average_power":
if log is not None and not isinstance(log, bool):
raise ValueError(
"log must be a boolean if transform_into == " '"average_power".'
'log must be a boolean if transform_into == "average_power".'
)
else:
if log is not None:
raise ValueError(
"log must be a None if transform_into == " '"csp_space".'
)
raise ValueError('log must be a None if transform_into == "csp_space".')
self.log = log

_validate_type(norm_trace, bool, "norm_trace")
Expand Down
8 changes: 4 additions & 4 deletions mne/decoding/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def __init__(self, info=None, scalings=None, with_mean=True, with_std=True):

if not (scalings is None or isinstance(scalings, (dict, str))):
raise ValueError(
"scalings type should be dict, str, or None, " f"got {type(scalings)}"
f"scalings type should be dict, str, or None, got {type(scalings)}"
)
if isinstance(scalings, str):
_check_option("scalings", scalings, ["mean", "median"])
if scalings is None or isinstance(scalings, dict):
if info is None:
raise ValueError(
'Need to specify "info" if scalings is' f"{type(scalings)}"
f'Need to specify "info" if scalings is {type(scalings)}'
)
self._scaler = _ConstantScaler(info, scalings, self.with_std)
elif scalings == "mean":
Expand Down Expand Up @@ -339,7 +339,7 @@ def inverse_transform(self, X):
X = np.asarray(X)
if X.ndim not in (2, 3):
raise ValueError(
"X should be of 2 or 3 dimensions but has shape " f"{X.shape}"
f"X should be of 2 or 3 dimensions but has shape {X.shape}"
)
return X.reshape(X.shape[:-1] + self.features_shape_)

Expand Down Expand Up @@ -642,7 +642,7 @@ def __init__(self, estimator, average=False):

if not isinstance(average, bool):
raise ValueError(
"average parameter must be of bool type, got " f"{type(bool)} instead"
f"average parameter must be of bool type, got {type(bool)} instead"
)

self.estimator = estimator
Expand Down
2 changes: 1 addition & 1 deletion mne/export/_egimff.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def export_evokeds_mff(fname, evoked, history=None, *, overwrite=False, verbose=
info = evoked[0].info
if np.round(info["sfreq"]) != info["sfreq"]:
raise ValueError(
"Sampling frequency must be a whole number. " f'sfreq: {info["sfreq"]}'
f'Sampling frequency must be a whole number. sfreq: {info["sfreq"]}'
)
sampling_rate = int(info["sfreq"])

Expand Down
2 changes: 1 addition & 1 deletion mne/forward/_field_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def _make_surface_mapping(
raise KeyError('surf must have both "rr" and "nn"')
if "coord_frame" not in surf:
raise KeyError(
"The surface coordinate frame must be specified " 'in surf["coord_frame"]'
'The surface coordinate frame must be specified in surf["coord_frame"]'
)
_check_option("mode", mode, ["accurate", "fast"])

Expand Down
4 changes: 2 additions & 2 deletions mne/gui/_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def _lock_fids_changed(self, change=None):
self._forward_widget_command(locked_widgets, "set_enabled", False)
self._forward_widget_command(fits_widgets, "set_enabled", False)
self._display_message(
"Placing MRI fiducials - " f"{self._current_fiducial.upper()}"
f"Placing MRI fiducials - {self._current_fiducial.upper()}"
)

self._set_sensors_visibility(self._lock_fids)
Expand All @@ -702,7 +702,7 @@ def _current_fiducial_changed(self, change=None):
self._follow_fiducial_view()
if not self._lock_fids:
self._display_message(
"Placing MRI fiducials - " f"{self._current_fiducial.upper()}"
f"Placing MRI fiducials - {self._current_fiducial.upper()}"
)

@observe("_info_file")
Expand Down
2 changes: 1 addition & 1 deletion mne/inverse_sparse/mxne_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def mixed_norm(
_check_option("alpha", alpha, ("sure",))
elif not 0.0 <= alpha < 100:
raise ValueError(
'If not equal to "sure" alpha must be in [0, 100). ' f"Got alpha = {alpha}"
f'If not equal to "sure" alpha must be in [0, 100). Got alpha = {alpha}'
)
if n_mxne_iter < 1:
raise ValueError(
Expand Down
4 changes: 1 addition & 3 deletions mne/inverse_sparse/mxne_optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,7 @@ def __call__(self, x): # noqa: D105
def norm(self, z, ord=2): # noqa: A002
"""Squared L2 norm if ord == 2 and L1 norm if order == 1."""
if ord not in (1, 2):
raise ValueError(
"Only supported norm order are 1 and 2. " f"Got ord = {ord}"
)
raise ValueError(f"Only supported norm order are 1 and 2. Got ord = {ord}")
stft_norm = stft_norm1 if ord == 1 else stft_norm2
norm = 0.0
if len(self.n_coefs) > 1:
Expand Down
2 changes: 1 addition & 1 deletion mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3007,7 +3007,7 @@ def _write_raw_buffer(fid, buf, cals, fmt):
write_function = write_complex128
else:
raise ValueError(
'only "single" and "double" supported for ' "writing complex data"
'only "single" and "double" supported for writing complex data'
)

buf = buf / np.ravel(cals)[:, None]
Expand Down
2 changes: 1 addition & 1 deletion mne/io/besa/besa.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _read_evoked_besa_avr(fname, verbose):
fields["DI"] = float(fields["DI"])
else:
raise RuntimeError(
'No "DI" field present. Could not determine ' "sampling frequency."
'No "DI" field present. Could not determine sampling frequency.'
)
if "TSB" in fields:
fields["TSB"] = float(fields["TSB"])
Expand Down
2 changes: 1 addition & 1 deletion mne/io/ctf/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
)
if not directory.endswith(".ds"):
raise TypeError(
'directory must be a directory ending with ".ds", ' f"got {directory}"
f'directory must be a directory ending with ".ds", got {directory}'
)
_check_option("system_clock", system_clock, ["ignore", "truncate"])
logger.info(f"ds directory : {directory}")
Expand Down
2 changes: 1 addition & 1 deletion mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ def _find_exclude_idx(ch_names, exclude, include=None):
if include: # find other than include channels
if exclude:
raise ValueError(
"'exclude' must be empty if 'include' is assigned. " f"Got {exclude}."
f"'exclude' must be empty if 'include' is assigned. Got {exclude}."
)
if isinstance(include, str): # regex for channel names
indices_include = []
Expand Down
2 changes: 1 addition & 1 deletion mne/io/fieldtrip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _remove_missing_channels_from_trial(trial, missing_chan_idx):
trial = np.delete(trial, missing_chan_idx, axis=0)
else:
raise ValueError(
'"trial" field of the FieldTrip structure ' "has an unknown format."
'"trial" field of the FieldTrip structure has an unknown format.'
)

return trial
Expand Down
2 changes: 1 addition & 1 deletion mne/io/kit/kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _set_stimchannels(inst, info, stim, stim_code):
stim = picks
else:
raise ValueError(
"stim needs to be list of int, '>' or " f"'<', not {str(stim)!r}"
f"stim needs to be list of int, '>' or '<', not {str(stim)!r}"
)
else:
stim = np.asarray(stim, int)
Expand Down
2 changes: 1 addition & 1 deletion mne/io/persyst/persyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, fname, preload=False, verbose=None):
curr_path, lay_fname = op.dirname(fname), op.basename(fname)
if not op.exists(fname):
raise FileNotFoundError(
f"The path you specified, " f'"{lay_fname}",does not exist.'
f'The path you specified, "{lay_fname}",does not exist.'
)

# sections and subsections currently unused
Expand Down
2 changes: 1 addition & 1 deletion mne/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ def write_labels_to_annot(
for fname in annot_fname:
if op.exists(fname):
raise ValueError(
f'File {fname} exists. Use "overwrite=True" to ' "overwrite it"
f'File {fname} exists. Use "overwrite=True" to overwrite it'
)

# prepare container for data to save:
Expand Down
2 changes: 1 addition & 1 deletion mne/minimum_norm/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ def _prepare_forward(
exp = float(exp)
if exp < 0:
raise ValueError(
"depth exponent should be greater than or " f"equal to 0, got {exp}"
f"depth exponent should be greater than or equal to 0, got {exp}"
)
exp = exp or None # alias 0. -> None

Expand Down
2 changes: 1 addition & 1 deletion mne/morph_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def read_morph_map(
return _read_morph_map(fname, subject_from, subject_to)
# if file does not exist, make it
logger.info(
f'Morph map "{fname}" does not exist, creating it and saving it to ' "disk"
f'Morph map "{fname}" does not exist, creating it and saving it to disk'
)
logger.info(log_msg % (subject_from, subject_to))
mmap_1 = _make_morph_map(subject_from, subject_to, subjects_dir, xhemi)
Expand Down
6 changes: 3 additions & 3 deletions mne/preprocessing/_csd.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def compute_current_source_density(
n_legendre_terms = _ensure_int(n_legendre_terms, "n_legendre_terms")
if n_legendre_terms < 1:
raise ValueError(
"n_legendre_terms must be greater than 0, " f"got {n_legendre_terms}"
f"n_legendre_terms must be greater than 0, got {n_legendre_terms}"
)

if isinstance(sphere, str) and sphere == "auto":
Expand All @@ -148,14 +148,14 @@ def compute_current_source_density(
x, y, z, radius = sphere
except Exception:
raise ValueError(
f'sphere must be "auto" or array-like with shape (4,), ' f"got {sphere}"
f'sphere must be "auto" or array-like with shape (4,), got {sphere}'
)
_validate_type(x, "numeric", "x")
_validate_type(y, "numeric", "y")
_validate_type(z, "numeric", "z")
_validate_type(radius, "numeric", "radius")
if radius <= 0:
raise ValueError("sphere radius must be greater than 0, " f"got {radius}")
raise ValueError("sphere radius must be greater than 0, got {radius}")

pos = np.array([inst.info["chs"][pick]["loc"][:3] for pick in picks])
if not np.isfinite(pos).all() or np.isclose(pos, 0.0).all(1).any():
Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def __repr__(self):
"""ICA fit information."""
infos = self._get_infos_for_repr()

s = f'{infos.fit_on or "no"} decomposition, ' f"method: {infos.fit_method}"
s = f'{infos.fit_on or "no"} decomposition, method: {infos.fit_method}'

if infos.fit_on is not None:
s += (
Expand Down
4 changes: 2 additions & 2 deletions mne/preprocessing/ieeg/_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def warp_montage(montage, moving, static, reg_affine, sdr_morph, verbose=None):
]
)
raise RuntimeError(
"Coordinate frame not supported, expected " f'"mri", got {bad_coord_frames}'
f'Coordinate frame not supported, expected "mri", got {bad_coord_frames}'
)
ch_names = list(ch_dict["ch_pos"].keys())
ch_coords = np.array([ch_dict["ch_pos"][name] for name in ch_names])
Expand Down Expand Up @@ -192,7 +192,7 @@ def make_montage_volume(
]
)
raise RuntimeError(
"Coordinate frame not supported, expected " f'"mri", got {bad_coord_frames}'
f'Coordinate frame not supported, expected "mri", got {bad_coord_frames}'
)

ch_names = list(ch_dict["ch_pos"].keys())
Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/stim.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def fix_stim_artifact(
s_end = int(np.ceil(inst.info["sfreq"] * tmax))
if (mode == "window") and (s_end - s_start) < 4:
raise ValueError(
"Time range is too short. Use a larger interval " 'or set mode to "linear".'
'Time range is too short. Use a larger interval or set mode to "linear".'
)
window = None
if mode == "window":
Expand Down
Loading

0 comments on commit 070ab62

Please sign in to comment.