From 6b6c71d5dab0884bbcc6703b949ccaedf0d0cffd Mon Sep 17 00:00:00 2001 From: Yusuf Gadelrab Date: Mon, 10 Aug 2026 23:42:00 +0000 Subject: [PATCH 1/2] fix: resolve Python 3.12 SyntaxWarning for invalid escape sequences in regex literals --- pyarabic/araby.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyarabic/araby.py b/pyarabic/araby.py index 0476a67..e79de32 100644 --- a/pyarabic/araby.py +++ b/pyarabic/araby.py @@ -271,14 +271,14 @@ # ~ """ all alef like letters """ LIGUATURES_PATTERN = re.compile(u"[" + u"".join(LIGUATURES) + u"]", re.UNICODE) # ~ """ all liguatures pattern """ -TOKEN_PATTERN = re.compile(u"([^\w\u0670\u064b-\u0652']+)", re.UNICODE) +TOKEN_PATTERN = re.compile(r"([^\w\u0670\u064b-\u0652']+)", re.UNICODE) # ~ """ pattern to tokenize a text""" -TOKEN_PATTERN_SPLIT = re.compile(u"([\w\u0670\u064b-\u0652']+)", re.UNICODE) +TOKEN_PATTERN_SPLIT = re.compile(r"([\w\u0670\u064b-\u0652']+)", re.UNICODE) # ~ """ pattern to tokenize a text with positions""" TOKEN_REPLACE = re.compile(u'\t|\r|\f|\v| ') # Arabic string -ARABIC_STRING = re.compile(u"([^\u0600-\u0652%s%s%s\s\d])" \ +ARABIC_STRING = re.compile(r"([^\u0600-\u0652%s%s%s\s\d])" \ % (LAM_ALEF, LAM_ALEF_HAMZA_ABOVE, LAM_ALEF_MADDA_ABOVE), re.UNICODE) # Arabic range ARABIC_RANGE = re.compile( @@ -1234,7 +1234,7 @@ def reduce_tashkeel(text): u"%s(?=%s)" % (FATHA, ALEF), \ # delete fatha from yeh and waw if they are in the word begining. - u"(?<=\s(%s|%s))%s" % (WAW, YEH, FATHA), \ + r"(?<=\s(%s|%s))%s" % (WAW, YEH, FATHA), \ # delete kasra if preceded by Hamza below alef. u"(?<=%s)%s" % (ALEF_HAMZA_BELOW, KASRA), \ @@ -1447,7 +1447,7 @@ def autocorrect(text): @rtype: unicode """ ## HARAKAT - text = re.sub(u"(?<=[\s\d])([%s])+"%(TASHKEEL_STRING),"",text, re.UNICODE) + text = re.sub(r"(?<=[\s\d])([%s])+"%(TASHKEEL_STRING),"",text, re.UNICODE) text = re.sub(u"^([%s])+"%(TASHKEEL_STRING),"",text , re.UNICODE) # tanwin on alef text = re.sub(ALEF+FATHATAN, FATHATAN + ALEF,text , re.UNICODE) From e9d16bace58779d48eb320d1cf74d5d51f0295b3 Mon Sep 17 00:00:00 2001 From: Yusuf Gadelrab Date: Thu, 13 Aug 2026 19:55:09 +0000 Subject: [PATCH 2/2] fix: complete Python 3.12+ SyntaxWarning cleanup in trans.py and araby_const.py The initial commit in this PR fixed araby.py, but three invalid escape sequences remained elsewhere in the package, so importing pyarabic still emitted SyntaxWarnings: - araby_const.py:271 - \w in TOKEN_PATTERN - trans.py:319 - \s \d \? \! \( \) in a character class - trans.py:518 - '\RL{' LaTeX delimiter in the __main__ demo All three are converted to raw strings, which is byte-identical for the trans.py cases. For araby_const.py the \uXXXX escapes move from Python to the re module, which supports them identically; equivalence was verified by differential testing (see PR description). trans.py CRLF line endings and UTF-8 BOM are preserved. --- pyarabic/araby_const.py | 2 +- pyarabic/trans.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyarabic/araby_const.py b/pyarabic/araby_const.py index 5abb204..5b61261 100644 --- a/pyarabic/araby_const.py +++ b/pyarabic/araby_const.py @@ -268,4 +268,4 @@ #~ """ all alef like letters """ LIGUATURES_PATTERN = re.compile(u"["+u"".join(LIGUATURES)+u"]", re.UNICODE) #~ """ all liguatures pattern """ -TOKEN_PATTERN = re.compile(u"[^\w\u064b-\u0652']+", re.UNICODE) +TOKEN_PATTERN = re.compile(r"[^\w\u064b-\u0652']+", re.UNICODE) diff --git a/pyarabic/trans.py b/pyarabic/trans.py index 965234a..0f8fae7 100644 --- a/pyarabic/trans.py +++ b/pyarabic/trans.py @@ -316,7 +316,7 @@ def segment_language(text): resultlist.append(('latin', actual_text)) arabic = True actual_text = k - elif re.search(u"[\s\d\?, :\!\(\)]", k): + elif re.search(r"[\s\d\?, :\!\(\)]", k): actual_text += k else: if arabic: @@ -515,7 +515,7 @@ def decode_tashkeel(word, marks, method = "ascii"): # test detect language text =u"""السلام عليكم how are you, لم اسمع أخبارك منذ مدة, where are you going""" print(arepr(segment_language(text))) - text_out= delimite_language(text, start='\RL{', end="}") + text_out= delimite_language(text, start=r'\RL{', end="}") print(text_out.encode('utf8')) text_out= delimite_language(text, start="", end="") print(text_out.encode('utf8'))