From fbaad42c0ed9f61bc4c04314317d33cffe604649 Mon Sep 17 00:00:00 2001 From: Sonic Build Admin Date: Tue, 16 Jun 2026 16:32:28 +0000 Subject: [PATCH] [sonic_pcie]: Fix regex string literals to use raw strings in pcie_common.py #### Description Updated regex patterns `p1` and `p2` in `PcieUtil.get_pcie_device()` to use raw string literals (`r"..."`) instead of plain string literals. #### Motivation and Context Python 3.12+ emits `DeprecationWarning` for invalid escape sequences in regular string literals (e.g., `\w`, `\s`, `\(`), and Python 3.13 raises a `SyntaxWarning` for these. Without raw strings, sequences like `\w` and `\s` are technically undefined escape sequences that happen to work today but will become `SyntaxError` in a future Python release. Using raw string literals (`r"..."`) is the correct and idiomatic way to write regex patterns in Python. #### How Has This Been Tested? - Verified the existing test suite passes: `pytest tests/pcie_common_test.py -v` - Confirmed no `DeprecationWarning` or `SyntaxWarning` is emitted under Python 3.12/3.13 - No behavioral change, the regex patterns themselves are identical #### Additional Information (Optional) This is a purely cosmetic/correctness fix. The regex logic and matched groups are unchanged. Signed-off-by: Sonic Build Admin --- sonic_platform_base/sonic_pcie/pcie_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic_platform_base/sonic_pcie/pcie_common.py b/sonic_platform_base/sonic_pcie/pcie_common.py index 127c614cd..35b708856 100644 --- a/sonic_platform_base/sonic_pcie/pcie_common.py +++ b/sonic_platform_base/sonic_pcie/pcie_common.py @@ -37,8 +37,8 @@ def load_config_file(self): def get_pcie_device(self): pciDict = {} pciList = [] - p1 = "^(\w+):(\w+)\.(\w)\s(.*)\s*\(*.*\)*" - p2 = "^.*:.*:.*:(\w+)\s*\(*.*\)*" + p1 = r"^(\w+):(\w+)\.(\w)\s(.*)\s*\(*.*\)*" + p2 = r"^.*:.*:.*:(\w+)\s*\(*.*\)*" command1 = ["sudo", "lspci"] command2 = ["sudo", "lspci", "-n"] # run command 1