Skip to content

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Oct 15, 2025

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.

@JukkaL JukkaL requested a review from ilevkivskyi October 15, 2025 14:45
@github-actions

This comment has been minimized.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for adding this.

@ilevkivskyi
Copy link
Member

Test failure on Python 3.9 seems to be caused by X | Y syntax for unions requires Python 3.10 error, please feel free to merge when you fix it.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL JukkaL merged commit 2eaafe9 into master Oct 16, 2025
20 checks passed
@JukkaL JukkaL deleted the cache-json-export branch October 16, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants