[ax_interface]: Fix Python 3.13 SyntaxWarning invalid escape sequence in socket_io.py - #387
Open
karthikbabu-CLS wants to merge 1 commit into
Conversation
… 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>
Collaborator
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
- What I did
Fixed Python 3.12+
SyntaxWarning: invalid escape sequence '\s'insrc/ax_interface/socket_io.pyby adding raw string prefix (r"...") to the regex pattern.- How I did it
The regex
re.compile("^agentxsocket\s+(.*)$", re.IGNORECASE)uses\sin a non-raw string. Python 3.12+ raises SyntaxWarning for invalid escape sequences in non-raw strings. Usingr"..."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$ show logging | grep "SyntaxWarning"0
admin@sonic:
admin@sonic:~$
- Which release branch to backport (provide reason below if selected)
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:
- Tested branch
- 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