django-stubs: mypy crashes with `TypeError: Object of type AnyType is not JSON serializable`

Bug report

mypy crashes at the end of successful check trying to write cache. Not sure if that’s django-stubs problem and can’t test if mypy works without django-stubs because of many type checks errors mypy doesn’t write cache at the end.

What’s wrong

  File "/opt/hostedtoolcache/Python/3.9.6/x64/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 87, 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 3021, in process_graph
  File "mypy/build.py", line 3138, in process_stale_scc
  File "mypy/build.py", line 2288, in write_cache
  File "mypy/build.py", line 1476, in write_cache
  File "mypy/build.py", line 1428, in json_dumps
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type AnyType is not JSON serializable

System information

  • OS:
  • python version: 3.9.6
  • django version: 3.2.7
  • mypy version: 0.910
  • django-stubs version: 1.9.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 26
  • Comments: 19 (14 by maintainers)

Most upvoted comments

Thanks! I think the bug is happening during cache write, not cache read, so I had to use --cache-dir=/dev/null instead.

Same issue here!