From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"John Snow" <jsnow@redhat.com>, "Kevin Wolf" <kwolf@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Mads Ynddal" <mads@ynddal.dk>
Subject: [PATCH 5/6] tracetool: complete typing annotations
Date: Wed, 8 Oct 2025 08:35:44 +0200 [thread overview]
Message-ID: <20251008063546.376603-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20251008063546.376603-1-pbonzini@redhat.com>
Add more annotations so that "mypy --strict". These have to be done
manually due to limitations of RightTyper.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scripts/tracetool/__init__.py | 30 +++++++++++++--------------
scripts/tracetool/backend/__init__.py | 2 +-
scripts/tracetool/format/log_stap.py | 2 +-
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 62895261a0d..c9509b327f4 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -19,17 +19,17 @@
import sys
from io import TextIOWrapper
from pathlib import PurePath
-from typing import Any, Iterator
+from typing import Any, Iterator, Sequence
import tracetool.backend
import tracetool.format
-def error_write(*lines) -> None:
+def error_write(*lines: str) -> None:
"""Write a set of error lines."""
sys.stderr.writelines("\n".join(lines) + "\n")
-def error(*lines):
+def error(*lines: str) -> None:
"""Write a set of error lines and exit."""
error_write(*lines)
sys.exit(1)
@@ -51,7 +51,7 @@ def error(*lines):
}
def expand_format_string(c_fmt: str, prefix: str="") -> str:
- def pri_macro_to_fmt(pri_macro):
+ def pri_macro_to_fmt(pri_macro: str) -> str:
assert pri_macro.startswith("PRI")
fmt_type = pri_macro[3] # 'd', 'i', 'u', or 'x'
fmt_size = pri_macro[4:] # '8', '16', '32', '64', 'PTR', 'MAX'
@@ -87,7 +87,7 @@ def out_open(filename: str) -> None:
out_filename = posix_relpath(filename)
out_fobj = open(filename, 'wt')
-def out(*lines, **kwargs) -> None:
+def out(*lines: str, **kwargs: Any) -> None:
"""Write a set of output lines.
You can use kwargs as a shorthand for mapping variables when formatting all
@@ -229,14 +229,14 @@ def c_type_to_rust(name: str) -> str:
class Arguments:
"""Event arguments description."""
- def __init__(self, args: list[tuple[str, str]]) -> None:
+ def __init__(self, args: Sequence[tuple[str, str] | Arguments]) -> None:
"""
Parameters
----------
args :
List of (type, name) tuples or Arguments objects.
"""
- self._args = []
+ self._args: list[tuple[str, str]] = []
for arg in args:
if isinstance(arg, Arguments):
self._args.extend(arg._args)
@@ -271,7 +271,7 @@ def build(arg_str: str) -> Arguments:
res.append((arg_type, identifier))
return Arguments(res)
- def __getitem__(self, index):
+ def __getitem__(self, index: int | slice) -> Arguments | tuple[str, str]:
if isinstance(index, slice):
return Arguments(self._args[index])
else:
@@ -287,7 +287,7 @@ def __len__(self) -> int:
def __str__(self) -> str:
"""String suitable for declaring function arguments."""
- def onearg(t, n):
+ def onearg(t: str, n: str) -> str:
if t[-1] == '*':
return "".join([t, n])
else:
@@ -298,7 +298,7 @@ def onearg(t, n):
else:
return ", ".join([ onearg(t, n) for t,n in self._args ])
- def __repr__(self):
+ def __repr__(self) -> str:
"""Evaluable string representation for this object."""
return "Arguments(\"%s\")" % str(self)
@@ -310,7 +310,7 @@ def types(self) -> list[str]:
"""List of argument types."""
return [ type_ for type_, _ in self._args ]
- def casted(self):
+ def casted(self) -> list[str]:
"""List of argument names casted to their type."""
return ["(%s)%s" % (type_, name) for type_, name in self._args]
@@ -321,7 +321,7 @@ def rust_decl_extern(self) -> str:
def rust_decl(self) -> str:
"""Return a Rust argument list for a tracepoint function"""
- def decl_type(type_):
+ def decl_type(type_: str) -> str:
if type_ == "const char *":
return "&std::ffi::CStr"
return c_type_to_rust(type_)
@@ -331,7 +331,7 @@ def decl_type(type_):
def rust_call_extern(self) -> str:
"""Return a Rust argument list for a call to an extern "C" function"""
- def rust_cast(name, type_):
+ def rust_cast(name: str, type_: str) -> str:
if type_ == "const char *":
return f"_{name}.as_ptr()"
return f"_{name}"
@@ -340,7 +340,7 @@ def rust_cast(name, type_):
def rust_call_varargs(self) -> str:
"""Return a Rust argument list for a call to a C varargs function"""
- def rust_cast(name, type_):
+ def rust_cast(name: str, type_: str) -> str:
if type_ == "const char *":
return f"_{name}.as_ptr()"
@@ -449,7 +449,7 @@ def build(line_str: str, lineno: int, filename: str) -> Event:
return Event(name, props, fmt, args, lineno, posix_relpath(filename))
- def __repr__(self):
+ def __repr__(self) -> str:
"""Evaluable string representation for this object."""
return "Event('%s %s(%s) %s')" % (" ".join(self.properties),
self.name,
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
index 645e78ece06..84bab3f42a0 100644
--- a/scripts/tracetool/backend/__init__.py
+++ b/scripts/tracetool/backend/__init__.py
@@ -122,7 +122,7 @@ def backend_modules(self) -> Iterator[Any]:
if module is not None:
yield module
- def _run_function(self, name: str, *args, check_trace_event_get_state: bool | None=None, **kwargs) -> None:
+ def _run_function(self, name: str, *args: Any, check_trace_event_get_state: bool | None=None, **kwargs: Any) -> None:
for backend in self.backend_modules():
func = getattr(backend, name % self._format, None)
if func is not None and \
diff --git a/scripts/tracetool/format/log_stap.py b/scripts/tracetool/format/log_stap.py
index d7ad0bb6a72..914e4674ffe 100644
--- a/scripts/tracetool/format/log_stap.py
+++ b/scripts/tracetool/format/log_stap.py
@@ -25,7 +25,7 @@
STATE_LITERAL = 1
STATE_MACRO = 2
-def c_macro_to_format(macro):
+def c_macro_to_format(macro: str) -> str:
if macro.startswith("PRI"):
return macro[3]
--
2.51.0
next prev parent reply other threads:[~2025-10-08 6:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 6:35 [PATCH 0/6] tracetool: add mypy --strict checking [AI discussion ahead!] Paolo Bonzini
2025-10-08 6:35 ` [PATCH 1/6] tracetool: rename variable with conflicting types Paolo Bonzini
2025-10-08 9:27 ` Daniel P. Berrangé
2025-10-08 18:06 ` Stefan Hajnoczi
2025-10-08 6:35 ` [PATCH 2/6] tracetool: apply isort and add check Paolo Bonzini
2025-10-08 9:29 ` Daniel P. Berrangé
2025-10-08 17:58 ` Stefan Hajnoczi
2025-10-09 7:52 ` Daniel P. Berrangé
2025-10-09 8:22 ` Paolo Bonzini
2025-10-09 8:58 ` Daniel P. Berrangé
2025-10-09 11:26 ` Paolo Bonzini
2025-10-09 12:05 ` Daniel P. Berrangé
2025-10-09 7:58 ` Paolo Bonzini
2025-10-08 6:35 ` [PATCH 3/6] tracetool: "import annotations" Paolo Bonzini
2025-10-08 9:31 ` Daniel P. Berrangé
2025-10-08 18:06 ` Stefan Hajnoczi
2025-10-08 6:35 ` [PATCH 4/6] tracetool: add type annotations Paolo Bonzini
2025-10-08 18:09 ` Stefan Hajnoczi
2025-10-08 6:35 ` Paolo Bonzini [this message]
2025-10-08 18:10 ` [PATCH 5/6] tracetool: complete typing annotations Stefan Hajnoczi
2025-10-08 6:35 ` [PATCH 6/6] tracetool: add typing checks to "make -C python check" Paolo Bonzini
2025-10-08 9:32 ` Daniel P. Berrangé
2025-10-08 18:12 ` Stefan Hajnoczi
2025-10-08 7:18 ` [PATCH 0/6] tracetool: add mypy --strict checking [AI discussion ahead!] Markus Armbruster
2025-10-08 10:34 ` Daniel P. Berrangé
2025-10-10 12:38 ` Markus Armbruster
2025-10-10 13:49 ` Paolo Bonzini
2025-10-10 17:41 ` Markus Armbruster
2025-10-08 10:40 ` Daniel P. Berrangé
2025-10-08 17:23 ` Stefan Hajnoczi
2025-10-08 17:41 ` Paolo Bonzini
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=20251008063546.376603-6-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mads@ynddal.dk \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).