[PATCH] perf tools: Stop using the deprecated argparse.FileType

From: Lalit Maganti

Date: Sat Nov 14 2026 - 19:35:26 EST


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@xxxxxxxxx/
Assisted-by: LLM
Signed-off-by: Lalit Maganti <lalitmaganti@xxxxxxxxx>
---
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