Skip to content

Conversation

@jsell-rh
Copy link
Contributor

@jsell-rh jsell-rh commented Dec 9, 2025

Closes #2268

Problem

When using apache-age-python with Python 3.6+, a SyntaxWarning is raised:

SyntaxWarning: invalid escape sequence '\s'
  WHITESPACE = re.compile('\s')

This warning occurs because \s is not a valid Python string escape sequence. While it currently works (Python interprets unrecognized escape sequences as literal backslash + character), this behavior is deprecated.

Solution

Use a raw string literal (r'\s') to properly declare the regex pattern. Raw strings treat backslashes as literal characters, which is the correct way to define regex patterns in Python.

Changes

File: age/age.py

  • Line 28: Changed WHITESPACE = re.compile('\s') to WHITESPACE = re.compile(r'\s')

Testing

  • ✅ Existing functionality unchanged (regex pattern behaves identically)
  • ✅ Warning eliminated when running with Python 3.12+
  • ✅ Forward compatible with Python 3.14+

References


Diff:

-WHITESPACE = re.compile('\s')
+WHITESPACE = re.compile(r'\s')

@MuhammadTahaNaveed MuhammadTahaNaveed merged commit 1bb95bf into apache:master Dec 11, 2025
7 checks passed
@MuhammadTahaNaveed
Copy link
Member

@jsell-rh Thank you for the fix.

@jsell-rh jsell-rh deleted the patch-1 branch December 11, 2025 19:03
jrgemignani pushed a commit to jrgemignani/age that referenced this pull request Dec 16, 2025
MuhammadTahaNaveed pushed a commit that referenced this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxWarning: invalid escape sequence '\s' in Python 3.12+

2 participants