wasmtime-py icon indicating copy to clipboard operation
wasmtime-py copied to clipboard

Type mismatch in signature of `wasmtime._value._unintern()`

Open moreati opened this issue 2 months ago • 3 comments

The function is declared as accepting a single Python int

https://github.com/bytecodealliance/wasmtime-py/blob/170aca9e40a76fbf5e1ee77ab5ba33c46f093318/wasmtime/_value.py#L28-L29

However in both call sites ctypes._Pointer[Any] is supplied

https://github.com/bytecodealliance/wasmtime-py/blob/170aca9e40a76fbf5e1ee77ab5ba33c46f093318/wasmtime/_store.py#L43-L45

https://github.com/bytecodealliance/wasmtime-py/blob/170aca9e40a76fbf5e1ee77ab5ba33c46f093318/wasmtime/_value.py#L181-L182

this was uncovered during investigation of #302 on a branch derived from the nox branch for #301. I believe it is not currently detected due to several cases of from ... import *. This issue is probably not a high priority or severity, I'm mainly recording it as a reminder to myself.

➜  wasmtime-py git:(nox) ✗ nox -p 3.14
nox > Running session tests-3.14
nox > Creating virtual environment (uv) using python3.14 in .nox/tests-3-14
nox > /Users/alex/.local/share/uv/tools/nox/bin/uv pip install '.[testing]'
nox > coverage run -m pytest
================================================ test session starts =================================================
platform darwin -- Python 3.14.0, pytest-8.4.2, pluggy-1.6.0
rootdir: /Users/alex/src/wasmtime-py
configfile: pytest.ini
plugins: mypy-1.0.1
collected 258 items                                                                                                  

ci/build-rust.py .F                                                                                            [  0%]
ci/cbindgen.py .                                                                                               [  1%]
...
wasmtime/loader.py .                                                                                           [100%]

====================================================== FAILURES ======================================================
____________________________________________________ test session ____________________________________________________
mypy exited with status 1.
_____________________________________________ [mypy] wasmtime/_store.py ______________________________________________
46: error: Argument 1 to "_unintern" has incompatible type "_Pointer[Any]"; expected "int"  [arg-type]
_____________________________________________ [mypy] wasmtime/_value.py ______________________________________________
184: error: Argument 1 to "_unintern" has incompatible type "_Pointer[Any]"; expected "int"  [arg-type]
======================================================== mypy ========================================================
Found 2 errors in 2 files (checked 154 source files)
============================================== short test summary info ===============================================
FAILED ci/build-rust.py::mypy-status
FAILED wasmtime/_store.py::mypy
FAILED wasmtime/_value.py::mypy
=========================================== 3 failed, 255 passed in 17.63s ===========================================
nox > Command coverage run -m pytest failed with exit code 1
nox > Session tests-3.14 failed.

moreati avatar Oct 27 '25 17:10 moreati

Oh dear! I ran across this recently and was also surprised at the lack of cast...

FWIW if there's something more modern than mypy to use nowadays (I've heard of pyright maybe?) I think it'd be reasonable to switch.

alexcrichton avatar Oct 27 '25 21:10 alexcrichton

Current contenders

  • MyPy - most mindshare, written in Python
  • PyRight - default Type Checker in VS Code Python extension. TypeScript
  • Ty - relative newcomer from makers of uv. Fast. Rust.
  • Pyre - newcomer from Meta. Fast, bleeding edge. Rust.

Python typing roles and details are still settling out, so each tool has varying interpretations. MyPy has the widest coverage (I think) and a slight presumption of being a reference for others. PyRight may be more agressive/bold about inferring types and highlighting things than MyPy - there are certainly some warnings I've seen in VS Code that MyPy in CI isn't mentioning, e.g.

https://github.com/bytecodealliance/wasmtime-py/blob/170aca9e40a76fbf5e1ee77ab5ba33c46f093318/wasmtime/_wasi.py#L13-L17

emits

Cannot access attribute "fspath" for class "bytearray" Attribute "__fspath__" is unknown Cannot access attribute "fspath" for class "memoryview[_I@memoryview]" Attribute "__fspath__" is unknown

moreati avatar Oct 28 '25 13:10 moreati

My experience so far is that mypy also isn't the best about ctypes in particular which is heavily used here. Do you know if any of the other type checkers is known for handling ctypes better? One option might be to run multiple type checkers in CI too

alexcrichton avatar Oct 29 '25 08:10 alexcrichton