Re: [PATCH v2 3/4] perf test: Suppress optparse deprecation warning with older pylint
From: Ian Rogers
Date: Wed Sep 30 2026 - 14:06:35 EST
On Wed, Sep 30, 2026 at 6:11 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> Python 3.13 reversed optparse's deprecation, and pylint 3.3.5 removed it
> from the deprecated-module list. Perf supports older pylint versions,
> so suppress the warning on this import and document the reason. Keep
> other deprecated-module diagnostics enabled.
>
> Link: https://docs.python.org/3.13/whatsnew/3.13.html#optparse
> Link: https://pylint.readthedocs.io/en/latest/whatsnew/3/3.3/index.html#what-s-new-in-pylint-3-3-5
> Fixes: 8a54784e708b ("perf build: Add pylint build tests")
> Reported-by: Aishwarya TCV <aishwarya.tcv@xxxxxxx>
> Assisted-by: Codex:gpt-6
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
> ---
> tools/perf/tests/shell/lib/attr.py | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/tests/shell/lib/attr.py b/tools/perf/tests/shell/lib/attr.py
> index 7f3d5b64b00dd7de45baff4f7d9baff89e003147..523257bcf8e126cb662af589727144bb26cff4d5 100644
> --- a/tools/perf/tests/shell/lib/attr.py
> +++ b/tools/perf/tests/shell/lib/attr.py
> @@ -4,7 +4,8 @@ import configparser
> import os
> import sys
> import glob
> -import optparse
> +# Pylint before 3.3.5 still treats optparse as deprecated.
> +import optparse # pylint: disable=deprecated-module
Thanks Leo! Could we just update to argparse here?
```
diff --git a/tools/perf/tests/shell/lib/attr.py
b/tools/perf/tests/shell/lib/attr.py
index 7f3d5b64b00d..68f06df9565a 100644
--- a/tools/perf/tests/shell/lib/attr.py
+++ b/tools/perf/tests/shell/lib/attr.py
@@ -4,7 +4,7 @@ import configparser
import os
import sys
import glob
-import optparse
+import argparse
import platform
import tempfile
import logging
@@ -426,29 +426,20 @@ def setup_log(verbose):
ch.setFormatter(formatter)
log.addHandler(ch)
-USAGE = '''%s [OPTIONS]
- -d dir # tests dir
- -p path # perf binary
- -t test # single test
- -v # verbose level
-''' % sys.argv[0]
-
def main():
- parser = optparse.OptionParser(usage=USAGE)
-
- parser.add_option("-t", "--test",
- action="store", type="string", dest="test")
- parser.add_option("-d", "--test-dir",
- action="store", type="string", dest="test_dir")
- parser.add_option("-p", "--perf",
- action="store", type="string", dest="perf")
- parser.add_option("-v", "--verbose",
- default=0, action="count", dest="verbose")
-
- options, args = parser.parse_args()
- if args:
- parser.error('FAILED wrong arguments %s' % ' '.join(args))
- return -1
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument("-t", "--test",
+ action="store", dest="test", help="single test")
+ parser.add_argument("-d", "--test-dir",
+ action="store", dest="test_dir", help="tests dir")
+ parser.add_argument("-p", "--perf",
+ action="store", dest="perf", help="perf binary")
+ parser.add_argument("-v", "--verbose",
+ default=0, action="count", dest="verbose",
+ help="verbose level")
+
+ options = parser.parse_args()
setup_log(options.verbose)
```
Thanks,
Ian
> import platform
> import tempfile
> import logging
>
> --
> 2.34.1
>