qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, "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>,
	"Mads Ynddal" <mads@ynddal.dk>
Subject: Re: [PATCH 4/6] tracetool: add type annotations
Date: Wed, 8 Oct 2025 14:09:27 -0400	[thread overview]
Message-ID: <20251008180927.GE181748@fedora> (raw)
In-Reply-To: <20251008063546.376603-5-pbonzini@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3773 bytes --]

On Wed, Oct 08, 2025 at 08:35:43AM +0200, Paolo Bonzini wrote:
> Created with a profiling-based tool, righttyper.  I used this script:
> 
>   python -m righttyper --generate-stubs --no-sampling --overwrite  -- ./tracetool.py --help
>   find . -name "*.pyi" | while read fname; do
>     merge-pyi --in-place -b bak.$fmt ${fname%i} $fname
>   done
> 
>   for fmt in c h rs d log-stap simpletrace-stap stap ust-events-c ust-events-h; do
>     find . -name '*.pyi*' | xargs rm
>     python -m righttyper --generate-stubs --no-sampling --overwrite ./tracetool.py \
>       --format=$fmt --backends=ust,simple,syslog,ftrace,dtrace,log --group=testsuite \
>       --binary=qemu --probe-prefix=qemu ../tests/tracetool/trace-events outfile.$fmt
>     find . -name "*.pyi" | while read fname; do
>       merge-pyi --in-place -b bak.$fmt ${fname%i} $fname
>     done
>   done
> 
>   python -m isort $(find tracetool -name "*.py")
> 
> Running the script took about 5 minutes.  The errors were mostly
> due to misunderstanding the "try_import" function:
> 
>   tracetool/backend/__init__.py:83: error: Incompatible types in assignment (expression has type Module, variable has type "tuple[bool, Module]")  [assignment]
>   tracetool/backend/__init__.py:117: error: Incompatible types in assignment (expression has type Module, variable has type "str")  [assignment]
>   tracetool/__init__.py:543: error: Incompatible return value type (got "tuple[bool, None]", expected "tuple[bool, Module]")  [return-value]
>   tracetool/format/__init__.py:60: error: Incompatible types in assignment (expression has type Module, variable has type "tuple[bool, Module]")  [assignment]
>   tracetool/format/__init__.py:85: error: Argument 2 to "try_import" has incompatible type "str"; expected "None"  [arg-type]
>   tracetool/format/__init__.py:88: error: Module not callable  [operator]
> 
> On top of this I fixed a little weirdness, while leaving the unannotated
> functions unchanged.  Being profiling-based, righttyper did not annotate
> anything not covered by the check-tracetool testsuite:
> - error cases
> - PRIxxx macros
> 
> It also reported list[Never] for always-empty lists, which is incorrect.
> Righttyper also has a few limitations: it does not annotate nested functions
> (there were only four of them), or "*args" argument lists.  These are fixed
> in the next patch.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  scripts/tracetool.py                         |  5 +-
>  scripts/tracetool/__init__.py                | 54 ++++++++++----------
>  scripts/tracetool/backend/__init__.py        | 19 +++----
>  scripts/tracetool/backend/dtrace.py          | 16 +++---
>  scripts/tracetool/backend/ftrace.py          | 10 ++--
>  scripts/tracetool/backend/log.py             | 10 ++--
>  scripts/tracetool/backend/simple.py          | 16 +++---
>  scripts/tracetool/backend/syslog.py          | 10 ++--
>  scripts/tracetool/backend/ust.py             |  8 +--
>  scripts/tracetool/format/__init__.py         |  7 +--
>  scripts/tracetool/format/c.py                |  5 +-
>  scripts/tracetool/format/d.py                |  5 +-
>  scripts/tracetool/format/h.py                |  5 +-
>  scripts/tracetool/format/log_stap.py         |  7 +--
>  scripts/tracetool/format/rs.py               |  5 +-
>  scripts/tracetool/format/simpletrace_stap.py |  5 +-
>  scripts/tracetool/format/stap.py             |  7 +--
>  scripts/tracetool/format/ust_events_c.py     |  5 +-
>  scripts/tracetool/format/ust_events_h.py     |  5 +-
>  19 files changed, 109 insertions(+), 95 deletions(-)

I skimmed through the type annotations and they look reasonable to me:

Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2025-10-08 18:10 UTC|newest]

Thread overview: 32+ 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 [this message]
2025-10-08  6:35 ` [PATCH 5/6] tracetool: complete typing annotations Paolo Bonzini
2025-10-08 18:10   ` 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
2025-10-14 19:02 ` Stefan Hajnoczi

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=20251008180927.GE181748@fedora \
    --to=stefanha@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=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).