* [PATCH] perf pmu-events: Fix jevents.py type annotations for mypy 2.x
@ 2026-10-18 6:53 Lalit Maganti
2026-10-18 6:55 ` sashiko-bot
2026-10-27 20:38 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 3+ messages in thread
From: Lalit Maganti @ 2026-10-18 6:53 UTC (permalink / raw)
To: irogers, acme, namhyung
Cc: james.clark, adrian.hunter, linux-perf-users, linux-kernel,
Lalit Maganti
Since the build runs mypy whenever it is installed, the perf build fails
with mypy 2.4 on 7 errors in jevents.py, e.g.:
pmu-events/jevents.py:542: error: Item "None" of "str | None" has no
attribute "replace" [union-attr]
pmu-events/jevents.py:563: error: Item "None" of "BigCString | None"
has no attribute "offsets" [union-attr]
Both come from wrong annotations rather than from code that can see
None:
- unit_to_pmu() is annotated as returning Optional[str] but always
returns a string, so JsonEvent.pmu is typed as optional where it is
used as a str.
- _bcs is set to None before the BigCString class is defined and only
assigned an instance after it, so mypy types it as BigCString | None.
Correct the return type and declare _bcs with its type instead of the
None placeholder. The generated pmu-events.c and pmu-events-string.c
are unchanged, and mypy 1.9 still passes.
Fixes: b3e9c396d0ac ("perf build: Make mypy build test opt-out (NO_MYPY=1)")
Assisted-by: LLM
Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
---
tools/perf/pmu-events/jevents.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index cc143f7e7cdf..080e04b51b8c 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -35,7 +35,7 @@ _pending_metrics: list["JsonEvent"] = []
# Name of metrics table to be written out
_pending_metrics_tblname: Optional[str] = None
# Global BigCString shared by all structures.
-_bcs = None
+_bcs: "BigCString"
# Map from the name of a metric group to a description of the group.
_metricgroups: Dict[str, str] = {}
# Order specific JsonEvent attributes will be visited.
@@ -262,7 +262,7 @@ class JsonEvent:
return fixed[name.lower()]
return event
- def unit_to_pmu(unit: Optional[str]) -> Optional[str]:
+ def unit_to_pmu(unit: Optional[str]) -> str:
"""Convert a JSON Unit to Linux PMU name."""
if not unit:
return 'default_core'
base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf pmu-events: Fix jevents.py type annotations for mypy 2.x
2026-10-18 6:53 [PATCH] perf pmu-events: Fix jevents.py type annotations for mypy 2.x Lalit Maganti
@ 2026-10-18 6:55 ` sashiko-bot
2026-10-27 20:38 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-18 6:55 UTC (permalink / raw)
To: Lalit Maganti; +Cc: linux-perf-users
> Since the build runs mypy whenever it is installed, the perf build fails
> with mypy 2.4 on 7 errors in jevents.py, e.g.:
>
> pmu-events/jevents.py:542: error: Item "None" of "str | None" has no
> attribute "replace" [union-attr]
> pmu-events/jevents.py:563: error: Item "None" of "BigCString | None"
> has no attribute "offsets" [union-attr]
>
> Both come from wrong annotations rather than from code that can see
> None:
> - unit_to_pmu() is annotated as returning Optional[str] but always
> returns a string, so JsonEvent.pmu is typed as optional where it is
> used as a str.
> - _bcs is set to None before the BigCString class is defined and only
> assigned an instance after it, so mypy types it as BigCString | None.
>
> Correct the return type and declare _bcs with its type instead of the
> None placeholder. The generated pmu-events.c and pmu-events-string.c
> are unchanged, and mypy 1.9 still passes.
>
> Fixes: b3e9c396d0ac ("perf build: Make mypy build test opt-out (NO_MYPY=1)")
> 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/20261018065345.918176-1-lalitmaganti@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf pmu-events: Fix jevents.py type annotations for mypy 2.x
2026-10-18 6:53 [PATCH] perf pmu-events: Fix jevents.py type annotations for mypy 2.x Lalit Maganti
2026-10-18 6:55 ` sashiko-bot
@ 2026-10-27 20:38 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-10-27 20:38 UTC (permalink / raw)
To: Lalit Maganti
Cc: irogers, namhyung, james.clark, adrian.hunter, linux-perf-users,
linux-kernel
On Sun, Oct 18, 2026 at 07:53:45AM +0100, Lalit Maganti wrote:
> Since the build runs mypy whenever it is installed, the perf build fails
> with mypy 2.4 on 7 errors in jevents.py, e.g.:
>
> pmu-events/jevents.py:542: error: Item "None" of "str | None" has no
> attribute "replace" [union-attr]
> pmu-events/jevents.py:563: error: Item "None" of "BigCString | None"
> has no attribute "offsets" [union-attr]
>
> Both come from wrong annotations rather than from code that can see
> None:
> - unit_to_pmu() is annotated as returning Optional[str] but always
> returns a string, so JsonEvent.pmu is typed as optional where it is
> used as a str.
> - _bcs is set to None before the BigCString class is defined and only
> assigned an instance after it, so mypy types it as BigCString | None.
>
> Correct the return type and declare _bcs with its type instead of the
> None placeholder. The generated pmu-events.c and pmu-events-string.c
> are unchanged, and mypy 1.9 still passes.
>
> Fixes: b3e9c396d0ac ("perf build: Make mypy build test opt-out (NO_MYPY=1)")
> Assisted-by: LLM
> Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
Looks ok,
Thanks, applied for v7.4.
- Arnaldo
> ---
> tools/perf/pmu-events/jevents.py | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
> index cc143f7e7cdf..080e04b51b8c 100755
> --- a/tools/perf/pmu-events/jevents.py
> +++ b/tools/perf/pmu-events/jevents.py
> @@ -35,7 +35,7 @@ _pending_metrics: list["JsonEvent"] = []
> # Name of metrics table to be written out
> _pending_metrics_tblname: Optional[str] = None
> # Global BigCString shared by all structures.
> -_bcs = None
> +_bcs: "BigCString"
> # Map from the name of a metric group to a description of the group.
> _metricgroups: Dict[str, str] = {}
> # Order specific JsonEvent attributes will be visited.
> @@ -262,7 +262,7 @@ class JsonEvent:
> return fixed[name.lower()]
> return event
>
> - def unit_to_pmu(unit: Optional[str]) -> Optional[str]:
> + def unit_to_pmu(unit: Optional[str]) -> str:
> """Convert a JSON Unit to Linux PMU name."""
> if not unit:
> return 'default_core'
>
> base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
> --
> 2.56.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-27 20:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-18 6:53 [PATCH] perf pmu-events: Fix jevents.py type annotations for mypy 2.x Lalit Maganti
2026-10-18 6:55 ` sashiko-bot
2026-10-27 20:38 ` Arnaldo Carvalho de Melo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.