Mypy Error : json.decoder.JSONDecodeError: Unterminated string starting at: line x column y (char z)

Viewed 585

I am running mypy version 0.910 against my django project in a docker container. Using this command:

mypy --install-types --non-interactive --config-file=../setup.cfg "$@"

It has been working wonderfully for the past 6 months or so, but sometimes this error arise:

Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/usr/local/lib/python3.6/dist-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 96, in main
  File "mypy/main.py", line 165, in run_build
  File "mypy/build.py", line 179, in build
  File "mypy/build.py", line 254, in _build
  File "mypy/build.py", line 2697, in dispatch
  File "mypy/build.py", line 3014, in process_graph
  File "mypy/build.py", line 3089, in process_fresh_modules
  File "mypy/build.py", line 1975, in load_tree
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 4925 (char 4924)
ERROR: 1

All I could do to fix this issue is fully rebuild the container. Could it be I have misconfigured something ?

2 Answers

I face the same problem when I run mypy inside the docker container (python 3.9.9) on Macbook with M1 processor. I guess it may be a sort of race condition like the mypy process is killed before it finishes writing to the cache file.

Workaround

For me using the --sqlite-cache flag helps.

Related