Skip to content

Commit b1c3284

Browse files
author
Benjamin Moody
committed
Merge pull request #416 into main
Avoid ambiguous backslashes in strings, which are confusing and generate warnings in newer python versions.
2 parents 21a7b52 + 9b2d6c3 commit b1c3284

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

tests/test_annotation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_1(self):
4444
target_aux_note = [None] * nannot
4545

4646
RXannot = re.compile(
47-
"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
47+
r"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
4848
)
4949

5050
for i in range(0, nannot):
@@ -117,7 +117,7 @@ def test_2(self):
117117
target_aux_note = [None] * nannot
118118

119119
RXannot = re.compile(
120-
"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
120+
r"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
121121
)
122122

123123
for i in range(0, nannot):
@@ -188,7 +188,7 @@ def test_3(self):
188188
target_aux_note = [None] * nannot
189189

190190
RXannot = re.compile(
191-
"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
191+
r"[ \t]*(?P<time>[\[\]\w\.:]+) +(?P<sample>\d+) +(?P<symbol>.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t?(?P<aux_note>.*)"
192192
)
193193

194194
for i in range(0, nannot):

wfdb/io/annotation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def check_field(self, field):
385385

386386
# Field specific checks
387387
if field == "record_name":
388-
if bool(re.search("[^-\w]", self.record_name)):
388+
if bool(re.search(r"[^-\w]", self.record_name)):
389389
raise ValueError(
390390
"record_name must only comprise of letters, digits, hyphens, and underscores."
391391
)
@@ -2394,9 +2394,9 @@ def update_extra_fields(subtype, chan, num, aux_note, update):
23942394
return subtype, chan, num, aux_note
23952395

23962396

2397-
rx_fs = re.compile("## time resolution: (?P<fs>\d+\.?\d*)")
2397+
rx_fs = re.compile(r"## time resolution: (?P<fs>\d+\.?\d*)")
23982398
rx_custom_label = re.compile(
2399-
"(?P<label_store>\d+) (?P<symbol>\S+) (?P<description>.+)"
2399+
r"(?P<label_store>\d+) (?P<symbol>\S+) (?P<description>.+)"
24002400
)
24012401

24022402

wfdb/io/record.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def check_field(self, field, required_channels="all"):
421421
# Record specification fields
422422
elif field == "record_name":
423423
# Allow letters, digits, hyphens, and underscores.
424-
accepted_string = re.match("[-\w]+", self.record_name)
424+
accepted_string = re.match(r"[-\w]+", self.record_name)
425425
if (
426426
not accepted_string
427427
or accepted_string.string != self.record_name
@@ -461,7 +461,7 @@ def check_field(self, field, required_channels="all"):
461461

462462
if field == "file_name":
463463
# Check for file_name characters
464-
accepted_string = re.match("[-\w]+\.?[\w]+", item[ch])
464+
accepted_string = re.match(r"[-\w]+\.?[\w]+", item[ch])
465465
if (
466466
not accepted_string
467467
or accepted_string.string != item[ch]
@@ -505,7 +505,7 @@ def check_field(self, field, required_channels="all"):
505505
"baseline values must be between -2147483648 (-2^31) and 2147483647 (2^31 -1)"
506506
)
507507
elif field == "units":
508-
if re.search("\s", item[ch]):
508+
if re.search(r"\s", item[ch]):
509509
raise ValueError(
510510
"units strings may not contain whitespaces."
511511
)
@@ -520,7 +520,7 @@ def check_field(self, field, required_channels="all"):
520520
"block_size values must be non-negative integers"
521521
)
522522
elif field == "sig_name":
523-
if re.search("\s", item[ch]):
523+
if re.search(r"\s", item[ch]):
524524
raise ValueError(
525525
"sig_name strings may not contain whitespaces."
526526
)
@@ -534,7 +534,7 @@ def check_field(self, field, required_channels="all"):
534534
# Segment names must be alphanumerics or just a single '~'
535535
if item[ch] == "~":
536536
continue
537-
accepted_string = re.match("[-\w]+", item[ch])
537+
accepted_string = re.match(r"[-\w]+", item[ch])
538538
if (
539539
not accepted_string
540540
or accepted_string.string != item[ch]

0 commit comments

Comments
 (0)