Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] perf tools: Stop using the deprecated argparse.FileType
@ 2026-11-15  0:35 Lalit Maganti
  2026-11-15  0:38 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Lalit Maganti @ 2026-11-15  0:35 UTC (permalink / raw)
  To: acme, namhyung, irogers
  Cc: adrian.hunter, james.clark, jolsa, mark.rutland,
	alexander.shishkin, peterz, mingo, linux-perf-users, linux-kernel,
	leo.yan, Lalit Maganti

Python 3.14 deprecates argparse.FileType, and pylint 4 warns about each
use of it. The perf build runs pylint and treats its warnings as errors,
so the default build fails:

  pmu-events/jevents.py:1494:26: W4904: Using deprecated class FileType of module argparse (deprecated-class)
  pmu-events/jevents.py:1496:33: W4904: Using deprecated class FileType of module argparse (deprecated-class)
  tests/shell/lib/perf_json_output_lint.py:23:31: W4904: Using deprecated class FileType of module argparse (deprecated-class)

Take plain file names and open the files after parsing, as the
deprecation warning suggests. The output of jevents.py is unchanged.

Fixes: 5fe83fb352c8 ("perf build: Make pylint build test opt-out (NO_PYLINT=1)")
Link: https://lore.kernel.org/linux-perf-users/20261018070110.927636-1-lalitmaganti@gmail.com/
Assisted-by: LLM
Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
---
 tools/perf/pmu-events/jevents.py                    | 12 ++++++++----
 tools/perf/tests/shell/lib/perf_json_output_lint.py |  8 ++++++--
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 080e04b51b8c..99b9813ca242 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -1490,11 +1490,15 @@ such as "arm/cortex-a34".''',
       type=dir_path,
       help='Root of tree containing architecture directories containing json files'
   )
-  ap.add_argument(
-      'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout)
-  ap.add_argument(
-      'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None)
+  ap.add_argument('output_file', nargs='?', default=None)
+  ap.add_argument('output_string_file', nargs='?', default=None)
   _args = ap.parse_args()
+  if _args.output_file:
+    _args.output_file = open(_args.output_file, 'w', encoding='utf-8')
+  else:
+    _args.output_file = sys.stdout
+  if _args.output_string_file:
+    _args.output_string_file = open(_args.output_string_file, 'w', encoding='utf-8')
 
   _args.output_file.write(f"""/* SPDX-License-Identifier: GPL-2.0 */
 /* THIS FILE WAS AUTOGENERATED BY `jevents.py arch={_args.arch} model={_args.model}` ! */
diff --git a/tools/perf/tests/shell/lib/perf_json_output_lint.py b/tools/perf/tests/shell/lib/perf_json_output_lint.py
index 8cde22ac9d97..1324dd8c9ec6 100644
--- a/tools/perf/tests/shell/lib/perf_json_output_lint.py
+++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py
@@ -20,10 +20,14 @@ ap.add_argument('--per-die', action='store_true')
 ap.add_argument('--per-node', action='store_true')
 ap.add_argument('--per-socket', action='store_true')
 ap.add_argument('--metric-only', action='store_true')
-ap.add_argument('--file', type=argparse.FileType('r'), default=sys.stdin)
+ap.add_argument('--file', default=None)
 args = ap.parse_args()
 
-Lines = args.file.readlines()
+if args.file:
+  with open(args.file, encoding='utf-8') as f:
+    Lines = f.readlines()
+else:
+  Lines = sys.stdin.readlines()
 
 def isfloat(num):
   try:

base-commit: a1c3b14c28ebfa79dd56e2743c2fbad0c02a7146
-- 
2.56.0


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

* Re: [PATCH] perf tools: Stop using the deprecated argparse.FileType
  2026-11-15  0:35 [PATCH] perf tools: Stop using the deprecated argparse.FileType Lalit Maganti
@ 2026-11-15  0:38 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-15  0:38 UTC (permalink / raw)
  To: Lalit Maganti; +Cc: linux-perf-users

> Python 3.14 deprecates argparse.FileType, and pylint 4 warns about each
> use of it. The perf build runs pylint and treats its warnings as errors,
> so the default build fails:
> 
>   pmu-events/jevents.py:1494:26: W4904: Using deprecated class FileType of module argparse (deprecated-class)
>   pmu-events/jevents.py:1496:33: W4904: Using deprecated class FileType of module argparse (deprecated-class)
>   tests/shell/lib/perf_json_output_lint.py:23:31: W4904: Using deprecated class FileType of module argparse (deprecated-class)
> 
> Take plain file names and open the files after parsing, as the
> deprecation warning suggests. The output of jevents.py is unchanged.
> 
> Fixes: 5fe83fb352c8 ("perf build: Make pylint build test opt-out (NO_PYLINT=1)")
> Link: https://lore.kernel.org/linux-perf-users/20261018070110.927636-1-lalitmaganti@gmail.com/
> Assisted-by: LLM
> Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115003507.1872482-1-lalitmaganti@gmail.com?part=1


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

end of thread, other threads:[~2026-11-15  0:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15  0:35 [PATCH] perf tools: Stop using the deprecated argparse.FileType Lalit Maganti
2026-11-15  0:38 ` sashiko-bot

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