diff mbox series

[v1] kselftest/devices/probe: fixed SintaxWarning for Python 3

Message ID 20240802161339.103709-1-alessandro.zanni87@gmail.com (mailing list archive)
State Accepted
Commit a19008256d05e726f29f43c6a307e45482c082c3
Headers show
Series [v1] kselftest/devices/probe: fixed SintaxWarning for Python 3 | expand

Commit Message

Alessandro Zanni Aug. 2, 2024, 4:13 p.m. UTC
Inserted raw strings because Python3 interpretes string literals as Unicode strings,
so '\d' is considered an invalid escaped sequence but this is not the case.
This fix avoids the "SyntaxWarning: invalid escape sequence '\d'" warning
for Python versions greater than 3.6.

Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
---

Notes:
    v1: inserted raw strings to avoid SyntaxWarning in Python3

 .../selftests/devices/probe/test_discoverable_devices.py      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Nícolas F. R. A. Prado Aug. 2, 2024, 9:26 p.m. UTC | #1
On Fri, Aug 02, 2024 at 06:13:37PM +0200, Alessandro Zanni wrote:
> Inserted raw strings because Python3 interpretes string literals as Unicode strings,
> so '\d' is considered an invalid escaped sequence but this is not the case.
> This fix avoids the "SyntaxWarning: invalid escape sequence '\d'" warning
> for Python versions greater than 3.6.
> 
> Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>

Hi,

thank you for the patch.

As described in 
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
you should

  Describe your changes in imperative mood, e.g. “make xyzzy do frotz” instead
  of “[This patch] makes xyzzy do frotz” or “[I] changed xyzzy to do frotz”,

So a better commit summary would be this:

kselftest/devices/probe: Fix SyntaxWarning in regex strings for Python 3

And similarly, in the commit message: "Insert raw strings...".

Also, this is fixing an issue in a previous commit, so you should add a tag for
that (before your Signed-off-by):

Fixes: dacf1d7a78bf ("kselftest: Add test to verify probe of devices from discoverable buses")

Other than that this looks good to me, so after making those changes in a v2 you
can add my

Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>

> ---
> 
> Notes:
>     v1: inserted raw strings to avoid SyntaxWarning in Python3

You don't need to add a changelog for v1, only starting with v2.

Thanks,
Nícolas
diff mbox series

Patch

diff --git a/tools/testing/selftests/devices/probe/test_discoverable_devices.py b/tools/testing/selftests/devices/probe/test_discoverable_devices.py
index d94a74b8a054..d7a2bb91c807 100755
--- a/tools/testing/selftests/devices/probe/test_discoverable_devices.py
+++ b/tools/testing/selftests/devices/probe/test_discoverable_devices.py
@@ -45,7 +45,7 @@  def find_pci_controller_dirs():
 
 
 def find_usb_controller_dirs():
-    usb_controller_sysfs_dir = "usb[\d]+"
+    usb_controller_sysfs_dir = r"usb[\d]+"
 
     dir_regex = re.compile(usb_controller_sysfs_dir)
     for d in os.scandir(sysfs_usb_devices):
@@ -91,7 +91,7 @@  def get_acpi_uid(sysfs_dev_dir):
 
 
 def get_usb_version(sysfs_dev_dir):
-    re_usb_version = re.compile("PRODUCT=.*/(\d)/.*")
+    re_usb_version = re.compile(r"PRODUCT=.*/(\d)/.*")
     with open(os.path.join(sysfs_dev_dir, "uevent")) as f:
         return int(re_usb_version.search(f.read()).group(1))