mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
perf pmu-events: Fix jevents.py type annotations for mypy 2.x
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: b3e9c396d0 ("perf build: Make mypy build test opt-out (NO_MYPY=1)")
Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
022b0ac5d3
commit
aa0fec5853
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user