mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Mypy hangs indefinitely trying to analyse a file with huge nested dicts

Open AlexWaygood opened this issue 2 years ago • 1 comments

Bug Report

Mypy hangs indefinitely when trying to analyse a file with huge nested dicts.

To Reproduce

  1. Copy and paste the contents of this file into a .py file: repro.txt
  2. Run mypy on the file
  3. Wait

Comments

This is similar to #14636. However, the dicts aren't nearly as deeply nested as in #14636, they're just very, very big.

The dicts are so huge because this is a partially generated file, the result of a codemod by stubdefaulter. Mypy is far from the only tool to have difficulty with this file: it also made black and flake8 hang, and crashed IDLE. Pyright did manage to analyse the file, but also took a lot longer than usual.

Your Environment

  • Mypy version used: 1.1.1; also master branch @ 2e75cbaa8e5c0fb8aa3548d5c7c8ccfd00131057
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.2

AlexWaygood avatar Mar 28 '23 16:03 AlexWaygood

We are facing this exact issue for a ~10k lines dictionary we codegen. Pyright and other tools don't have issues.

dgellow avatar Aug 27 '24 15:08 dgellow

+1 seeing most performance hits come from deeply nested dictionaries.

njgrisafi avatar Sep 13 '24 16:09 njgrisafi

Mypy compiled on current master type-checks the original 15MB file in under 10 sec. I don't think we need to keep this open.

ilevkivskyi avatar Jul 30 '25 00:07 ilevkivskyi

Nice!

AlexWaygood avatar Jul 30 '25 06:07 AlexWaygood