near / wasmtime

Standalone JIT-style runtime for WebAssembly, using Cranelift
https://wasmtime.dev/
Apache License 2.0
3 stars 4 forks source link

Add type annotations to zkasm-result.py #208

Closed akashin closed 5 months ago

akashin commented 5 months ago

This should make the code safer and easier to read.

To verify the types you can run:

pdm run mypy
akashin commented 5 months ago

Multiple dicts have Any as value type. Would it be possible to use more narrow types instead? This might also help to make relationships between functions that operate on the same type of dict more clear. For instance the relationship between read_summary and write_summary.

I suppose using more narrow types is optional, as for a CI script it might be sufficient to fail at runtime if a dict contains unexpected types.

Yes, it is definitely possible. I think it makes sense for read_summary and write_summary, although instead of narrowing the Any type I think we should introduce a Summary type instead of dict.

For to_csv_record and from_csv_record I don't think there is much value in narrowing Any type as that wouldn't improve the type-checking anywhere.

mooori commented 5 months ago

Noticed that pdm run mypy could be added here too:

https://github.com/near/wasmtime/blob/41bb3255a24ba3b33708a9fdbdc0803ab9b12c78/docs/zkasm/usage.md?plain=1#L102-L108