You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KeyError: 'deprecated' because of bad cache #18473
I ran mypy in my venv and the cache somehow got into a bad state, leading to crashes until the cache was removed. I don't know what triggered this. If it matters, the mypy that caused the bad cache was installed with faster-cache.
Traceback
Traceback (most recent call last):
File "[...]/.venv/bin/mypy", line 8, in <module>
sys.exit(console_entry())
~~~~~~~~~~~~~^^
File "[...]/.venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
main()
~~~~^^
File "mypy/main.py", line 109, in main
File "mypy/main.py", line 193, in run_build
File "mypy/build.py", line 194, in build
File "mypy/build.py", line 269, in _build
File "mypy/build.py", line 2940, in dispatch
File "mypy/build.py", line 3331, in process_graph
File "mypy/build.py", line 3409, in process_fresh_modules
File "mypy/build.py", line 2096, in load_tree
File "mypy/nodes.py", line 402, in deserialize
File "mypy/nodes.py", line 4058, in deserialize
File "mypy/nodes.py", line 3999, in deserialize
File "mypy/nodes.py", line 263, in deserialize
File "mypy/nodes.py", line 3420, in deserialize
File "mypy/nodes.py", line 4058, in deserialize
File "mypy/nodes.py", line 3999, in deserialize
File "mypy/nodes.py", line 263, in deserialize
File "mypy/nodes.py", line 952, in deserialize
File "mypy/nodes.py", line 879, in deserialize
KeyError: 'deprecated'
Facing the same issue here. @ncoghlan thanks for the suggestion, though I get an error when passing --no-incremental - probably specific to my config: error: --install-types not supported with incremental mode disabled
I am using mypy through pre-commit, if anyone else has a similar config, would appreciate any workarounds! Thanks
Thanks for providing the repro, @injust. I experimented with it but cannot reproduce the crash. The only difference that I am aware of is that I am working on Windows.
The deprecated decorator has been supported since Mypy 1.14. For each function definition (FuncDef), an attribute called "deprecated" (that handles the deprecation message or is None/null) should be available in the cache. However, this is not the case for any of the function definitions stored in tokenize.data.json. I randomly picked another file in the cache ( enum.data.json), and it contains information on "deprecated" for the function definitions I checked.
I cannot imagine a way how the serialisation of a function definition could be incomplete in such a way because the related method returns either a complete dictionary or nothing:
It's hard to tell what went wrong for me. My only idea is that tokenize.data.json could have been created by an older Mypy version and was not updated when a newer one was applied. Not very likely, I guess.
Are there any hints on how the cash became corrupted?
(@hauntsaninja: Do you think something like this could happen when switching between versions with fast-cache enabled and disabled?)
I (used to) run mypy through the command-line (installed in my venv) and also through pre-commit (as a commit hook or pre-commit run -a), but I'm not sure running through pre-commit uses/modifies the same .mypy_cache/ directory.
Perhaps using both and/or their versions being out of sync could have caused this problem?
Activity
ncoghlan commentedon Jan 27, 2025
Workaround if anyone else runs into this: pass
--no-incrementalto amypyrun and the full run will fix up the corrupted cache.harith-mindway commentedon Feb 24, 2025
Facing the same issue here.
@ncoghlan thanks for the suggestion, though I get an error when passing
--no-incremental- probably specific to my config:error: --install-types not supported with incremental mode disabledI am using mypy through pre-commit, if anyone else has a similar config, would appreciate any workarounds! Thanks
injust commentedon Feb 24, 2025
I also happen to be using mypy through pre-commit 🤔
tyralla commentedon Jun 14, 2025
Thanks for providing the repro, @injust. I experimented with it but cannot reproduce the crash. The only difference that I am aware of is that I am working on Windows.
The
deprecateddecorator has been supported since Mypy 1.14. For each function definition (FuncDef), an attribute called "deprecated" (that handles the deprecation message or isNone/null) should be available in the cache. However, this is not the case for any of the function definitions stored intokenize.data.json. I randomly picked another file in the cache (enum.data.json), and it contains information on "deprecated" for the function definitions I checked.The
data_mtimeinformation of all cached files:I cannot imagine a way how the serialisation of a function definition could be incomplete in such a way because the related method returns either a complete dictionary or nothing:
mypy/mypy/nodes.py
Lines 860 to 876 in 5081c59
It's hard to tell what went wrong for me. My only idea is that
tokenize.data.jsoncould have been created by an older Mypy version and was not updated when a newer one was applied. Not very likely, I guess.Are there any hints on how the cash became corrupted?
(@hauntsaninja: Do you think something like this could happen when switching between versions with
fast-cacheenabled and disabled?)injust commentedon Jun 14, 2025
I (used to) run mypy through the command-line (installed in my venv) and also through pre-commit (as a commit hook or
pre-commit run -a), but I'm not sure running through pre-commit uses/modifies the same.mypy_cache/directory.Perhaps using both and/or their versions being out of sync could have caused this problem?
tyralla commentedon Jun 14, 2025
Maybe. I don't know.
Does the crash still occur with Mypy 1.15 and 1.16?
injust commentedon Jun 14, 2025
No, at least I haven't run into this crash since I reported it.
tyralla commentedon Jun 14, 2025
@ncoghlan @harith-mindway @tomasvotava @victorbadenas
Can you confirm the problem went away for (unknown) reasons? I think we could close this issue, then.
tomasvotava commentedon Jun 14, 2025
Well the problem still appears from time to time, but deleting .mypy_cache always helps.
tyralla commentedon Jun 14, 2025
And it is always because of
KeyError: 'deprecated'? (And eventually only happens when analysingtokenizeor other specific modules?)victorbadenas commentedon Jun 25, 2025