Skip to content

Fix Python 3.14 SyntaxWarnings for invalid escape sequences#962

Closed
sacsant wants to merge 1 commit into
open-power:masterfrom
sacsant:warnings
Closed

Fix Python 3.14 SyntaxWarnings for invalid escape sequences#962
sacsant wants to merge 1 commit into
open-power:masterfrom
sacsant:warnings

Conversation

@sacsant

@sacsant sacsant commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Convert regular strings with escape sequences to raw strings
(r'...') to fix SyntaxWarnings that appear with Python 3.14.
These warnings occur because escape sequences like
[, (, $, \d, \w are invalid in regular strings and will not work
in future Python versions.

Files modified:

  • common/OPexpect.py: Fixed regex patterns with [, \d
  • common/OpTestIPMI.py: Fixed regex patterns with (
  • common/OpTestUtil.py: Fixed prompt patterns and sed
    commands with [, $, \x1b
  • common/OpTestHost.py: Fixed regex patterns
  • testcases/*.py: Fixed various regex patterns and escape sequences

All changes use raw strings (r'...') which treat backslashes literally,
making them suitable for regex patterns and shell commands.
The changes are backward compatible with older Python versions.

Signed-off-by: Sachin Sant sachinp@linux.ibm.com

@sacsant

sacsant commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Without the fix several warning with --help:

.......
.......
/home/sachin/test/op-test/common/OPexpect.py:74: SyntaxWarning: "[" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\["? A raw string is also an option.
"[[0-9. ]+,0] Assert fail:",
/home/sachin/test/op-test/common/OPexpect.py:75: SyntaxWarning: "[" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\["? A raw string is also an option.
"[[0-9. ]+,[0-9]] Unexpected exception",
/home/sachin/test/op-test/common/OPexpect.py:116: SyntaxWarning: "\d" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\d"? A raw string is also an option.
"Rebooting in \d+ seconds",
.......
.......

With the fix no warnings. The import error issue is fixed via separate PR

./op-test --help
Traceback (most recent call last):
File "/home/sachin/test/op-test/./op-test", line 29, in
from testcases import HelloWorld
File "/home/sachin/test/op-test/testcases/HelloWorld.py", line 31, in
import OpTestConfiguration
File "/home/sachin/test/op-test/OpTestConfiguration.py", line 7, in
from common.OpTestBMC import OpTestBMC, OpTestSMC
File "/home/sachin/test/op-test/common/OpTestBMC.py", line 44, in
from .OpTestIPMI import OpTestIPMI
File "/home/sachin/test/op-test/common/OpTestIPMI.py", line 47, in
from .OpTestUtil import OpTestUtil
File "/home/sachin/test/op-test/common/OpTestUtil.py", line 36, in
import telnetlib
ModuleNotFoundError: No module named 'telnetlib'

Convert regular strings with escape sequences to raw
strings (r'...') to fix SyntaxWarnings that appear with
Python 3.14. These warnings occur because escape sequences
like \[, \(, $, \d, \w are invalid in regular strings and
will not work in future Python versions.

Files modified:
- common/OPexpect.py: Fixed regex patterns with \[, \d
- common/OpTestIPMI.py: Fixed regex patterns with \(
- common/OpTestUtil.py: Fixed prompt patterns and sed
  commands with \[, $, \x1b
- common/OpTestHost.py: Fixed regex patterns
- testcases/*.py: Fixed various regex patterns and escape sequences

All changes use raw strings (r'...') which treat backslashes literally,
making them suitable for regex patterns and shell commands. The changes
are backward compatible with older Python versions.

Signed-off-by: Sachin Sant <sachinp@linux.ibm.com>
@sacsant

sacsant commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased to latest master. There was an additional/unwanted file included in the commit. Updated the code to correct it.

@PraveenPenguin

Copy link
Copy Markdown
Collaborator

Thanks for PR @sacsant but it seems not needed as the master branch has fix .. Closing this PR .. If you again face an issue please open new PR

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