Skip to content

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

Closed

Description

@jsell-rh

Describe the bug
The apache-age-python library triggers warnings in Python 3.6+ due to invalid escape sequences in regex patterns. In Python 3.12+, this was upgraded from a DeprecationWarning to a SyntaxWarning, and will become a hard error (SyntaxError) in Python 3.14+.

How are you accessing AGE (Command line, driver, etc.)?

  • Python driver (apache-age-python version 0.0.7)

What data setup do we need to do?
None - this warning occurs during module import and basic connection setup.

What is the necessary configuration info needed?

  • Python 3.6+ (warning becomes more visible in Python 3.12+)
  • apache-age-python 0.0.7

What is the command that caused the error?

import age
import psycopg2

# Warning appears during import or when using the library
conn = psycopg2.connect(...)
age.setUpAge(conn, "test_graph")

Warning output:

Python 3.6-3.11:

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

Python 3.12+:

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

Expected behavior
No warnings should be emitted. Regex patterns should use raw string literals (r'\s') to properly declare escape sequences.

Root Cause
In age/age.py line 28, the code uses:

WHITESPACE = re.compile('\s')

The \s is not a valid Python string escape sequence. While it currently works because Python interprets unrecognized escape sequences as literal characters, this behavior is deprecated.

Proposed Fix (#2267)
Change line 28 to use a raw string:

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

This is backwards compatible and eliminates the warning across all Python versions.

Environment (please complete the following information):

  • apache-age-python Version: 0.0.7
  • Python Version: 3.12+ (but affects 3.6+)
  • PostgreSQL + AGE: Any version

Additional context

  • bpo-27364 - Python 3.6 introduced DeprecationWarning for invalid escape sequences
  • Python 3.12 What's New - Upgraded to SyntaxWarning in 3.12
  • Python 3.14+ will likely make this a hard SyntaxError

Activity

  1. added
    bug
    on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions