Skip to content

Commit

Permalink
Apply ruff/flake8-implicit-str-concat rule ISC001 (pydicom#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed May 6, 2024
1 parent 6cf9c33 commit 3118444
Show file tree
Hide file tree
Showing 30 changed files with 121 additions and 153 deletions.
4 changes: 2 additions & 2 deletions src/pydicom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def DS_numpy(use_numpy: bool = True) -> None:

if use_DS_decimal and use_numpy:
raise ValueError(
"Cannot use numpy arrays to read DS elements" "if `use_DS_decimal` is True"
"Cannot use numpy arrays to read DS elements if `use_DS_decimal` is True"
)
use_DS_numpy = use_numpy

Expand Down Expand Up @@ -120,7 +120,7 @@ def DS_decimal(use_Decimal_boolean: bool = True) -> None:
use_DS_decimal = use_Decimal_boolean

if use_DS_decimal and use_DS_numpy:
raise ValueError("Cannot set use_DS_decimal True " "if use_DS_numpy is True")
raise ValueError("Cannot set use_DS_decimal True if use_DS_numpy is True")

import pydicom.valuerep

Expand Down
2 changes: 1 addition & 1 deletion src/pydicom/encaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def fragment_frame(frame: bytes, nr_fragments: int = 1) -> Iterator[bytes]:
# Add 1 to fix odd length frames not being caught
if nr_fragments > (frame_length + 1) / 2.0:
raise ValueError(
"Too many fragments requested (the minimum fragment size is " "2 bytes)"
"Too many fragments requested (the minimum fragment size is 2 bytes)"
)

length = int(frame_length / nr_fragments)
Expand Down
2 changes: 1 addition & 1 deletion src/pydicom/filereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ def read_deferred_data_element(
statinfo = os.stat(filename_or_obj)
if statinfo.st_mtime != timestamp:
warn_and_log(
"Deferred read warning -- file modification time has " "changed"
"Deferred read warning -- file modification time has changed"
)

# Open the file, position to the right place
Expand Down
2 changes: 1 addition & 1 deletion src/pydicom/fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ def write(
"""
if not path and self.path is None:
raise ValueError(
"The path to the root directory is required for a " "new File-set"
"The path to the root directory is required for a new File-set"
)

if path and self.path:
Expand Down
2 changes: 1 addition & 1 deletion src/pydicom/fileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _try_read_encapsulated_pixel_data(

length = fp.read(4)
if length != b"\0\0\0\0":
msg = "Expected 4 zero bytes after undefined length delimiter " "at pos {0:04x}"
msg = "Expected 4 zero bytes after undefined length delimiter at pos {0:04x}"
logger.debug(msg.format(fp.tell() - 4))

if defer_size is not None and defer_size <= byte_count:
Expand Down
2 changes: 1 addition & 1 deletion src/pydicom/jsonrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def get_element_values(self) -> Any:
if self.value_key == "Value":
if not isinstance(self.value, list):
raise TypeError(
f"'{self.value_key}' of data element '{self.tag}' must " "be a list"
f"'{self.value_key}' of data element '{self.tag}' must be a list"
)

if not self.value:
Expand Down
2 changes: 1 addition & 1 deletion src/pydicom/pixels/decoders/rle.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _rle_parse_header(header: bytes) -> list[int]:
nr_segments = unpack("<L", header[:4])[0]
if nr_segments > 15:
raise ValueError(
"The RLE header specifies an invalid number of segments " f"({nr_segments})"
f"The RLE header specifies an invalid number of segments ({nr_segments})"
)

return list(unpack(f"<{nr_segments}L", header[4 : 4 * (nr_segments + 1)]))
2 changes: 1 addition & 1 deletion src/pydicom/util/leanread.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,5 @@ def data_element_generator(
yield ((group, elem), vr, length, None, value_tell)
else:
raise NotImplementedError(
"This reader does not handle undefined length except " "for SQ"
"This reader does not handle undefined length except for SQ"
)
12 changes: 5 additions & 7 deletions src/pydicom/valuerep.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def __new__( # type: ignore[misc]
match = cls._regex_dt.match(val)
if not match or len(val) > 26:
raise ValueError(
f"Unable to convert non-conformant value '{val}' to 'DT' " "object"
f"Unable to convert non-conformant value '{val}' to 'DT' object"
)

dt_match = match.group(2)
Expand Down Expand Up @@ -847,7 +847,7 @@ def __new__( # type: ignore[misc]
match = cls._RE_TIME.match(val)
if not match:
raise ValueError(
f"Unable to convert non-conformant value '{val}' to 'TM' " "object"
f"Unable to convert non-conformant value '{val}' to 'TM' object"
)

hour = int(match.group("h"))
Expand Down Expand Up @@ -1075,7 +1075,7 @@ def __init__(
if not is_valid_ds(str(self)):
# This will catch nan and inf
raise ValueError(
f'Value "{str(self)}" is not valid for elements with a VR ' "of DS"
f'Value "{str(self)}" is not valid for elements with a VR of DS'
)

def __eq__(self, other: Any) -> Any:
Expand Down Expand Up @@ -1212,9 +1212,7 @@ def __init__(
warn_and_log(msg)
if not is_valid_ds(repr(self).strip("'")):
# This will catch nan and inf
msg = (
f'Value "{str(self)}" is not valid for elements with a VR ' "of DS"
)
msg = f'Value "{str(self)}" is not valid for elements with a VR of DS'
if validation_mode == config.RAISE:
raise ValueError(msg)
warn_and_log(msg)
Expand Down Expand Up @@ -1320,7 +1318,7 @@ def __init__(
elif isinstance(val, IS | ISfloat) and hasattr(val, "original_string"):
self.original_string = val.original_string
if validation_mode:
msg = f'Value "{str(self)}" is not valid for elements with a VR ' "of IS"
msg = f'Value "{str(self)}" is not valid for elements with a VR of IS'
if validation_mode == config.WARN:
warn_and_log(msg)
elif validation_mode == config.RAISE:
Expand Down
10 changes: 5 additions & 5 deletions tests/pixels/test_decoder_rle.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def test_8bit_3sample(self):

def test_16bit_1sample(self):
"""Test decoding 16-bit, 1 sample/pixel."""
header = b"\x02\x00\x00\x00" b"\x40\x00\x00\x00" b"\x47\x00\x00\x00"
header = b"\x02\x00\x00\x00\x40\x00\x00\x00\x47\x00\x00\x00"
header += (64 - len(header)) * b"\x00"
# 2 x 3 data
data = (
Expand Down Expand Up @@ -771,7 +771,7 @@ def test_noop(self):
b"\x80"
)
assert bytes(_rle_decode_segment(data)) == (
b"\x01\x02\x03\x04\x05\x06" b"\x01\x01\x01"
b"\x01\x02\x03\x04\x05\x06\x01\x01\x01"
)

# data at start, noop middle, data at end
Expand All @@ -782,14 +782,14 @@ def test_noop(self):
b"\x80"
)
assert bytes(_rle_decode_segment(data)) == (
b"\x01\x02\x03\x04\x05\x06" b"\x01\x01\x01"
b"\x01\x02\x03\x04\x05\x06\x01\x01\x01"
)

# data at start, noop end
# Copy 6 bytes literally, then 3 x 0x01
data = b"\x05\x01\x02\x03\x04\x05\x06" b"\xFE\x01" b"\x80"
data = b"\x05\x01\x02\x03\x04\x05\x06\xFE\x01\x80"
assert bytes(_rle_decode_segment(data)) == (
b"\x01\x02\x03\x04\x05\x06" b"\x01\x01\x01"
b"\x01\x02\x03\x04\x05\x06\x01\x01\x01"
)

def test_literal(self):
Expand Down
6 changes: 2 additions & 4 deletions tests/pixels/test_encoder_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ def test_buffer_64(self):
runner.set_options(**opts)
runner.set_source(src_a)
assert runner.get_frame(None) == (
b"\x00\x00\x00\x00\x00\x00\x00\x00" b"\x01\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"
)

runner.set_option("columns", 3)
Expand Down Expand Up @@ -1443,9 +1443,7 @@ def test_specify_plugin_encoding_exception(self):
@pytest.mark.skipif(not HAVE_NP or HAVE_RLE, reason="Numpy unavailable")
def test_encoding_exceptions(self):
"""Test an encoding exception occurring in all plugins"""
msg = (
"Unable to encode as exceptions were raised by all available " "plugins:\n"
)
msg = "Unable to encode as exceptions were raised by all available plugins:\n"
with pytest.raises(RuntimeError, match=msg):
RLELosslessEncoder.encode(EXPL_16_16_1F.ds, byteorder=">")

Expand Down
4 changes: 1 addition & 3 deletions tests/pixels/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,9 +1510,7 @@ def test_voi_uint16_array_float(self):
item.LUTDescriptor = [4, 0, 16]
item.LUTData = [0, 127, 32768, 65535]
arr = np.asarray([0, 1, 2, 3, 255], dtype="float64")
msg = (
r"Applying a VOI LUT on a float input array may give " r"incorrect results"
)
msg = r"Applying a VOI LUT on a float input array may give incorrect results"

with pytest.warns(UserWarning, match=msg):
out = apply_voi(arr, ds)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_JPEG_LS_transfer_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from pydicom.filereader import dcmread
from pydicom.data import get_testdata_file

pillow_missing_message = "pillow is not available " "in this test environment"
pillow_missing_message = "pillow is not available in this test environment"
pillow_present_message = "pillow is being tested"
gdcm_missing_message = "GDCM is not available in this test environment"
numpy_missing_message = "numpy is not available " "in this test environment"
jpeg_ls_missing_message = "jpeg_ls is not available " "in this test environment"
numpy_missing_message = "numpy is not available in this test environment"
jpeg_ls_missing_message = "jpeg_ls is not available in this test environment"


try:
Expand Down
26 changes: 12 additions & 14 deletions tests/test_charset.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def test_invalid_character_set(self, allow_reading_invalid_values):
ds.SpecificCharacterSet = "UNSUPPORTED"
with pytest.warns(
UserWarning,
match=(
"Unknown encoding 'UNSUPPORTED' " "- using default encoding instead"
),
match=("Unknown encoding 'UNSUPPORTED' - using default encoding instead"),
):
ds.decode()
assert "CompressedSamples^CT1" == ds.PatientName
Expand Down Expand Up @@ -174,7 +172,7 @@ def test_bad_encoded_single_encoding(self, allow_reading_invalid_values):
elem = DataElement(0x00100010, "PN", b"\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2")

with pytest.warns(
UserWarning, match="Failed to decode byte string " "with encoding 'UTF8'"
UserWarning, match="Failed to decode byte string with encoding 'UTF8'"
):
pydicom.charset.decode_element(elem, ["ISO_IR 192"])
assert "���������" == elem.value
Expand Down Expand Up @@ -209,7 +207,7 @@ def test_convert_encodings_warnings(self):
"""Test warning if stand-alone encodings are used as code extension"""
with pytest.warns(
UserWarning,
match="Value 'GBK' cannot be used as " "code extension, ignoring it",
match="Value 'GBK' cannot be used as code extension, ignoring it",
):
encodings = pydicom.charset.convert_encodings(
["ISO_IR 126", "GBK", "ISO 2022 IR 144", "ISO_IR 192"]
Expand Down Expand Up @@ -239,7 +237,7 @@ def test_bad_decoded_multi_byte_encoding(self, allow_reading_invalid_values):

with pytest.warns(
UserWarning,
match="Failed to decode byte string " "with encodings: iso2022_jp_2",
match="Failed to decode byte string with encodings: iso2022_jp_2",
):
pydicom.charset.decode_element(elem, ["ISO 2022 IR 159"])
assert "���������" == elem.value
Expand Down Expand Up @@ -267,7 +265,7 @@ def test_unknown_escape_sequence(self, allow_reading_invalid_values):

with pytest.warns(
UserWarning,
match="Found unknown escape sequence " "in encoded string value",
match="Found unknown escape sequence in encoded string value",
):
pydicom.charset.decode_element(elem, ["ISO_IR 100"])
assert "\x1b-FÄéïíõóéïò" == elem.value
Expand All @@ -279,7 +277,7 @@ def test_unknown_escape_sequence_enforce_standard(self, enforce_valid_values):
0x00100010, "PN", b"\x1b\x2d\x46\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2"
)
with pytest.raises(
ValueError, match="Found unknown escape sequence " "in encoded string value"
ValueError, match="Found unknown escape sequence in encoded string value"
):
pydicom.charset.decode_element(elem, ["ISO_IR 100"])

Expand Down Expand Up @@ -314,7 +312,7 @@ def test_patched_charset(self, allow_reading_invalid_values):
elem = DataElement(0x00100010, "PN", b"Buc^J\xc3\xa9r\xc3\xb4me")
with pytest.warns(
UserWarning,
match="Unknown encoding 'ISOIR 192' - " "using default encoding instead",
match="Unknown encoding 'ISOIR 192' - using default encoding instead",
):
pydicom.charset.decode_element(elem, ["ISOIR 192"])

Expand All @@ -328,7 +326,7 @@ def test_patched_code_extension_charset(self):
elem = DataElement(
0x00100010,
"PN",
b"Dionysios=\x1b\x2d\x46" b"\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
b"Dionysios=\x1b\x2d\x46\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
)
# correct encoding
pydicom.charset.decode_element(elem, ["ISO 2022 IR 100", "ISO 2022 IR 126"])
Expand All @@ -344,7 +342,7 @@ def test_patched_code_extension_charset(self):
elem = DataElement(
0x00100010,
"PN",
b"Dionysios=\x1b\x2d\x46" b"\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
b"Dionysios=\x1b\x2d\x46\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
)
pydicom.charset.decode_element(elem, ["ISO_2022-IR 100", "ISO 2022 IR 126"])

Expand All @@ -359,7 +357,7 @@ def test_patched_code_extension_charset(self):
elem = DataElement(
0x00100010,
"PN",
b"Dionysios=\x1b\x2d\x46" b"\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
b"Dionysios=\x1b\x2d\x46\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
)
pydicom.charset.decode_element(elem, ["ISO 2022 IR 100", "ISO_2022_IR+126"])
assert "Dionysios=Διονυσιος" == elem.value
Expand All @@ -380,7 +378,7 @@ def test_single_byte_multi_charset_personname(self):
elem = DataElement(
0x00100010,
"PN",
b"Dionysios=\x1b\x2d\x46" b"\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
b"Dionysios=\x1b\x2d\x46\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
)
pydicom.charset.decode_element(elem, ["ISO 2022 IR 100", "ISO 2022 IR 126"])
assert "Dionysios=Διονυσιος" == elem.value
Expand All @@ -403,7 +401,7 @@ def test_single_byte_multi_charset_text(self):
elem = DataElement(
0x00081039,
"LO",
b"Dionysios is \x1b\x2d\x46" b"\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
b"Dionysios is \x1b\x2d\x46\xc4\xe9\xef\xed\xf5\xf3\xe9\xef\xf2",
)
pydicom.charset.decode_element(elem, ["ISO 2022 IR 100", "ISO 2022 IR 126"])
assert "Dionysios is Διονυσιος" == elem.value
Expand Down
2 changes: 1 addition & 1 deletion tests/test_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_cid3111(self):
)

def test_cid3263(self):
meaning = "12-lead from EASI leads (ES, AS, AI)" " by Dower/EASI transformation"
meaning = "12-lead from EASI leads (ES, AS, AI) by Dower/EASI transformation"
assert (
codes.cid3263._12LeadFromEASILeadsESASAIByDowerEASITransformation
== Code(
Expand Down
4 changes: 1 addition & 3 deletions tests/test_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ def test_get_testdata_file_no_download(self, recwarn):
def test_get_testdata_file_network_outage(self, download_failure):
"""Test a network outage when using get_testdata_file."""
fname = "693_UNCI.dcm"
msg = (
r"A download failure occurred while attempting to " r"retrieve 693_UNCI.dcm"
)
msg = r"A download failure occurred while attempting to retrieve 693_UNCI.dcm"
with pytest.warns(UserWarning, match=msg):
assert get_testdata_file(fname) is None

Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataelem.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def test_invalid_ui(self, value):
self.check_invalid_vr("UR", value)

@pytest.mark.parametrize(
"value", ("1234.567890.333", "0.0.0", "1234." * 12 + "1234" "", None)
"value", ("1234.567890.333", "0.0.0", "1234." * 12 + "1234", None)
)
def test_valid_ui(self, value):
self.check_valid_vr("UI", value)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def test_attribute_error_in_property(self):
ds.PixelData = "xyzlmnop"
msg_from_gdcm = r"'Dataset' object has no attribute 'filename'"
msg_from_numpy = (
r"'FileMetaDataset' object has no attribute " "'TransferSyntaxUID'"
r"'FileMetaDataset' object has no attribute 'TransferSyntaxUID'"
)
msg_from_pillow = r"'Dataset' object has no attribute " "'PixelRepresentation'"
msg_from_pillow = r"'Dataset' object has no attribute 'PixelRepresentation'"
msg = "(" + "|".join([msg_from_gdcm, msg_from_numpy, msg_from_pillow]) + ")"
with pytest.raises(AttributeError, match=msg):
ds.pixel_array
Expand Down Expand Up @@ -1281,7 +1281,7 @@ def test_invalid_private_creator(self):
ds.add_new(0x00250011, "LO", "Valid Creator")
ds.add_new(0x00251007, "UN", "foobar")
ds.add_new(0x00251107, "UN", "foobaz")
msg = r"\(0025,0010\) '\[13975, 13802]' " r"is not a valid private creator"
msg = r"\(0025,0010\) '\[13975, 13802]' is not a valid private creator"
with pytest.warns(UserWarning, match=msg):
assert (
str(ds[0x00251007]) == "(0025,1007) Private tag data"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_add_entry(self):

def test_add_entry_raises_for_private_tag(self):
with pytest.raises(
ValueError, match="Private tags cannot be " 'added using "add_dict_entries"'
ValueError, match='Private tags cannot be added using "add_dict_entries"'
):
add_dict_entry(0x10011101, "DS", "Test One", "Test One")

Expand All @@ -101,7 +101,7 @@ def test_add_entries_raises_for_private_tags(self):
0x10011002: ("DS", "3", "Test Two", "", "TestTwo"),
}
with pytest.raises(
ValueError, match="Private tags cannot be added " 'using "add_dict_entries"'
ValueError, match='Private tags cannot be added using "add_dict_entries"'
):
add_dict_entries(new_dict_items)

Expand Down
Loading

0 comments on commit 3118444

Please sign in to comment.