mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: TAKANO Mitsuhiro <takano32@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	TAKANO Mitsuhiro <takano32@gmail.com>
Subject: [PATCH] perf build: Replace the deprecated FileType with a helper
Date: Wed, 25 Nov 2026 17:33:15 +0000	[thread overview]
Message-ID: <20261125173315.2359128-1-takano32@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-25 17:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125173315.2359128-1-takano32@gmail.com \
    --to=takano32@gmail.com \
    --cc=acme@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®