* [PATCH] perf build: Replace the deprecated FileType with a helper
@ 2026-11-25 17:33 TAKANO Mitsuhiro
0 siblings, 0 replies; only message in thread
From: TAKANO Mitsuhiro @ 2026-11-25 17:33 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
linux-perf-users, linux-kernel, TAKANO Mitsuhiro
pylint-tests and pylint-pmu-events hang off `all`, so with a pylint that
reports W4904 the build fails on a tree nobody has changed. Measured on
7.4-rc4 with Python 3.14.9 and pylint 4.0.5, both targets exit 2 and
pylint reports:
- W4904 deprecated-class, argparse.FileType: pmu-events/jevents.py:1494
and :1496, tests/shell/lib/perf_json_output_lint.py:23
FileType is deprecated in the class's own terms - the docstring in 3.14
reads "Deprecated factory for creating file object types" - so the two
jevents call sites and the one in the JSON output linter are replaced by
a helper that opens the file, or hands back stdout or stdin for '-',
which is what FileType did. The reader names its encoding, as the rest
of the Python in perf does.
Verification: pylint-tests and pylint-pmu-events exit 2 and 2 before this
change and 0 and 0 after it. The generated pmu-events tables are byte
identical either side of the change, checked by running jevents.py for
arm64 and x86 over the same input tree and comparing pmu-events.c and
pmu-events-string.c.
Written with Hermes Agent, an LLM assistant; the author reviewed it and
ran the build and the generator as described.
Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com>
---
tools/perf/pmu-events/jevents.py | 19 ++++++++++++++++---
.../tests/shell/lib/perf_json_output_lint.py | 11 ++++++++++-
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index e083f7495e67..6974c58951a3 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -7,7 +7,7 @@ import json
import metric
import os
import sys
-from typing import (Callable, Dict, Optional, Sequence, Set, Tuple)
+from typing import (Callable, Dict, Optional, Sequence, Set, TextIO, Tuple)
import collections
# Global command line arguments.
@@ -1450,6 +1450,19 @@ def _init_worker(std_events: dict) -> None:
global _arch_std_events
_arch_std_events = std_events
+def open_output(path: str) -> TextIO:
+ """Open path for writing, or hand back stdout for '-'.
+
+ argparse.FileType is deprecated (its own docstring says so in 3.14) and
+ pylint 4 reports it, which fails the pylint-pmu-events target `all` needs.
+ """
+ if path == '-':
+ return sys.stdout
+ try:
+ return open(path, 'w', encoding='utf-8')
+ except OSError as exc:
+ raise argparse.ArgumentTypeError(str(exc)) from exc
+
def main() -> None:
global _args
@@ -1491,9 +1504,9 @@ such as "arm/cortex-a34".''',
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)
+ 'output_file', type=open_output, nargs='?', default=sys.stdout)
ap.add_argument(
- 'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None)
+ 'output_string_file', type=open_output, nargs='?', default=None)
_args = ap.parse_args()
_args.output_file.write(f"""/* SPDX-License-Identifier: GPL-2.0 */
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..9aafd03a8114 100644
--- a/tools/perf/tests/shell/lib/perf_json_output_lint.py
+++ b/tools/perf/tests/shell/lib/perf_json_output_lint.py
@@ -6,6 +6,15 @@ import argparse
import sys
import json
+def open_input(path):
+ """Open path for reading, or hand back stdin for '-'."""
+ if path == '-':
+ return sys.stdin
+ try:
+ return open(path, encoding='utf-8')
+ except OSError as exc:
+ raise argparse.ArgumentTypeError(str(exc)) from exc
+
ap = argparse.ArgumentParser()
ap.add_argument('--no-args', action='store_true')
ap.add_argument('--interval', action='store_true')
@@ -20,7 +29,7 @@ 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', type=open_input, default=sys.stdin)
args = ap.parse_args()
Lines = args.file.readlines()
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-25 17:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 17:33 [PATCH] perf build: Replace the deprecated FileType with a helper TAKANO Mitsuhiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®