Commit 2eaafe9
authored
Add tool to convert binary cache files to JSON (#20071)
Work to enable #19697 (see the issue for motivation).
Copy the old `serialize` methods with some modifications and use them in
the export tool. This will let us remove the old `serialize` and
`deserialize` methods once we drop support for the old JSON
serialization format at some point.
This should be enough to support existing use cases that inspect the
JSON files. Instead of directly inspecting them, users will have to run
the tool first if they use the binary cache format. Example:
```
$ python -m mypy.exportjson .mypy_cache/3.13/foobar.data.ff
.mypy_cache/3.13/foobar.data.ff -> .mypy_cache/3.13/foobar.data.ff.json
```
The run generates the `.mypy_cache/3.13/foobar.data.ff.json` file, which
is similar to existing to cache json files.
I added some tests and manually checked that the JSON file for
`builtins` module is identical to the one generated by mypy. However, we
won't guarantee that all new symbol table or cache features will be
added to the exporter, to simplify maintenance. Also I didn't test all
features of the exporter in the tests -- I just ensure that the basics
work. The tool is primarily there to support existing use cases and
debugging workflows, and it would be better to use `MypyFile.read(...)`
in new use cases that require cache inspection.1 parent 2c6c395 commit 2eaafe9
File tree
4 files changed
+929
-0
lines changed- mypy
- test
- test-data/unit
4 files changed
+929
-0
lines changed
0 commit comments