Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v2] kselftest/devices/probe: Fix SyntaxWarning in regex strings for Python 3
@ 2024-08-05 10:37 Alessandro Zanni
  2024-08-05 22:07 ` Shuah Khan
  0 siblings, 1 reply; 2+ messages in thread
From: Alessandro Zanni @ 2024-08-05 10:37 UTC (permalink / raw)
  To: shuah, gregkh, nfraprado, skhan
  Cc: Alessandro Zanni, linux-kselftest, linux-kernel

Insert raw strings to prevent Python3 from interpreting string literals as Unicode strings
and, consequently, '\d' as an invalid escaped sequence.
Avoid the 'SyntaxWarning: invalid escape sequence '\d'' warning for Python versions greater than 3.6.

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

Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
---

Notes:
    v2: Imperative mode description for the inserted changes, added previous commit tag fixed by this patch

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

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))
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] kselftest/devices/probe: Fix SyntaxWarning in regex strings for Python 3
  2024-08-05 10:37 [PATCH v2] kselftest/devices/probe: Fix SyntaxWarning in regex strings for Python 3 Alessandro Zanni
@ 2024-08-05 22:07 ` Shuah Khan
  0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2024-08-05 22:07 UTC (permalink / raw)
  To: Alessandro Zanni, shuah, gregkh, nfraprado
  Cc: linux-kselftest, linux-kernel, Shuah Khan

On 8/5/24 04:37, Alessandro Zanni wrote:
> Insert raw strings to prevent Python3 from interpreting string literals as Unicode strings
> and, consequently, '\d' as an invalid escaped sequence.
> Avoid the 'SyntaxWarning: invalid escape sequence '\d'' warning for Python versions greater than 3.6.
> 

Change log lines shouldn't exceed 76 chars - Refer the to following doc

Documentation/process/submitting-patches.rst

Include the exact warning you are seeing when you run the script.

> Fixes: dacf1d7a78bf ("kselftest: Add test to verify probe of devices from discoverable buses")
> 
> Reviewed-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
> ---
> 
> Notes:
>      v2: Imperative mode description for the inserted changes, added previous commit tag fixed by this patch
> 
>   .../selftests/devices/probe/test_discoverable_devices.py      | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> 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))
>   

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-05 22:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-05 10:37 [PATCH v2] kselftest/devices/probe: Fix SyntaxWarning in regex strings for Python 3 Alessandro Zanni
2024-08-05 22:07 ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox