Skip to content

[ax_interface]: Fix Python 3.13 SyntaxWarning invalid escape sequence in socket_io.py - #387

Open
karthikbabu-CLS wants to merge 1 commit into
sonic-net:masterfrom
karthikbabu-CLS:user/karthikbabu/socket-io-syntax-warning-fix
Open

[ax_interface]: Fix Python 3.13 SyntaxWarning invalid escape sequence in socket_io.py#387
karthikbabu-CLS wants to merge 1 commit into
sonic-net:masterfrom
karthikbabu-CLS:user/karthikbabu/socket-io-syntax-warning-fix

Conversation

@karthikbabu-CLS

Copy link
Copy Markdown

- What I did
Fixed Python 3.12+ SyntaxWarning: invalid escape sequence '\s' in src/ax_interface/socket_io.py by adding raw string prefix (r"...") to the regex pattern.

- How I did it
The regex re.compile("^agentxsocket\s+(.*)$", re.IGNORECASE) uses \s in a non-raw string. Python 3.12+ raises SyntaxWarning for invalid escape sequences in non-raw strings. Using r"..." raw string prefix is the standard fix — it tells Python to treat backslashes literally, which is the correct behavior for regex patterns.

- How to verify it
Verified on community SONiC VS image (x86_64-kvm_x86_64-r0):

BEFORE:

2026 Aug 20 05:39:33.913162 sonic INFO snmp#supervisord: snmp-subagent /usr/local/lib/python3.13/dist-packages/ax_interface/socket_io.py:38: SyntaxWarning: invalid escape sequence '\s'

AFTER:

admin@sonic:$ show logging | grep "SyntaxWarning" | wc -l
0
admin@sonic:
$ show logging | grep "SyntaxWarning"
admin@sonic:~$

- Which release branch to backport (provide reason below if selected)

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202605

Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:

- Tested branch

  • master
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202605
  • N/A

- Test result

master: SONiC.master.0-dirty-20260820.165606 - SyntaxWarning absent after fix (verified on sonic-vs)

- Description for the changelog

Fix Python 3.13 SyntaxWarning invalid escape sequence '\s' in ax_interface/socket_io.py

… in socket_io.py

Replace re.compile("^agentxsocket\s+(.*)$") with raw string
re.compile(r"^agentxsocket\s+(.*)$") at line 38.
In Python 3.12+, '\s' in a non-raw string raises SyntaxWarning.

Tested on sonic-vs (SONiC master 1658c9049):
Before: SyntaxWarning logged at snmp container startup from ax_interface/socket_io.py:38
After: show logging | grep SyntaxWarning | wc -l → 0

Signed-off-by: Karthik Babu Harichandra Babu <karthikbabu@celestica.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants