Skip to content

Commit ee649fb

Browse files
NightTsarinaukleinek
authored andcommitted
Fix "invalid escape sequence" errors
Starting with Python 3.12 during byte compilation the following warnings are emitted: /usr/lib/python3/dist-packages/hamster/lib/datetime.py:471: SyntaxWarning: invalid escape sequence '\s' position="exact", separator="\s+", default_day=None, ref="now"): /usr/lib/python3/dist-packages/hamster/lib/datetime.py:472: SyntaxWarning: invalid escape sequence '\s' """Parse a start-end range from text. /usr/lib/python3/dist-packages/hamster/widgets/activityentry.py:381: SyntaxWarning: invalid escape sequence '\s' fragments = [f for f in re.split("[\s|#]", text)] /usr/lib/python3/dist-packages/hamster/widgets/timeinput.py:141: SyntaxWarning: invalid escape sequence '\D' numbers = re.split("\D", str_time) Fix them by using raw strings or quoting as appropriate.
1 parent 81be67e commit ee649fb

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/hamster/lib/datetime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ def format(self, default_day=None, explicit_none=True):
468468

469469
@classmethod
470470
def parse(cls, text,
471-
position="exact", separator="\s+", default_day=None, ref="now"):
471+
position="exact", separator=r"\s+", default_day=None, ref="now"):
472472
"""Parse a start-end range from text.
473473
474474
position (str): "exact" to match exactly the full text
475475
"head" to search only at the beginning of text, and
476476
"tail" to search only at the end.
477477
478-
separator (str): regexp pattern (e.g. '\s+') meant to separate the datetime
478+
separator (str): regexp pattern (e.g. r'\\s+') meant to separate the datetime
479479
from the rest. Discarded for "exact" position.
480480
481481
default_day (date): If start is given without any date (e.g. just hh:mm),

src/hamster/widgets/activityentry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def update_suggestions(self, text=""):
378378
break
379379

380380

381-
fragments = [f for f in re.split("[\s|#]", text)]
381+
fragments = [f for f in re.split(r"[\s|#]", text)]
382382
current_fragment = fragments[-1] if fragments else ""
383383

384384

src/hamster/widgets/timeinput.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def figure_time(self, str_time):
138138

139139
# strip everything non-numeric and consider hours to be first number
140140
# and minutes - second number
141-
numbers = re.split("\D", str_time)
141+
numbers = re.split(r"\D", str_time)
142142
numbers = [x for x in numbers if x!=""]
143143

144144
hours, minutes = None, None

0 commit comments

Comments
 (0)