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 <[email protected]>
> ---
> 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 <[email protected]>
signature.asc
Description: PGP signature
