Skip to content

Commit

Permalink
Add --debug-serialize option (#14155)
Browse files Browse the repository at this point in the history
Currently, `mypy_primer` sets `--cache-dir=/dev/null` which disables
cache generation. This can result in errors being missed which would
normally come up during `tree.serialize()`. Removing
`--cache-dir=/dev/null` isn't practical.

This PR adds a new debug / test option `--debug-serialize` which runs
`tree.serialize()` even if cache generation is disabled to help detect
serialize errors earlier.

**Refs**
* #14137
*
hauntsaninja/mypy_primer#54 (review)

cc: @hauntsaninja
  • Loading branch information
cdce8p authored Dec 19, 2022
1 parent 97d9ed5 commit d5dc1fb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,12 @@ def write_cache(self) -> None:
or self.options.cache_dir == os.devnull
or self.options.fine_grained_incremental
):
if self.options.debug_serialize:
try:
self.tree.serialize()
except Exception:
print(f"Error serializing {self.id}", file=self.manager.stdout)
raise # Propagate to display traceback
return
is_errors = self.transitive_error
if is_errors:
Expand Down
3 changes: 3 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,9 @@ def add_invertible_flag(
parser.add_argument(
"--cache-map", nargs="+", dest="special-opts:cache_map", help=argparse.SUPPRESS
)
# --debug-serialize will run tree.serialize() even if cache generation is disabled.
# Useful for mypy_primer to detect serialize errors earlier.
parser.add_argument("--debug-serialize", action="store_true", help=argparse.SUPPRESS)
# This one is deprecated, but we will keep it for few releases.
parser.add_argument(
"--enable-incomplete-features", action="store_true", help=argparse.SUPPRESS
Expand Down
3 changes: 3 additions & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ def __init__(self) -> None:
# Read cache files in fine-grained incremental mode (cache must include dependencies)
self.use_fine_grained_cache = False

# Run tree.serialize() even if cache generation is disabled
self.debug_serialize = False

# Tune certain behaviors when being used as a front-end to mypyc. Set per-module
# in modules being compiled. Not in the config file or command line.
self.mypyc = False
Expand Down

0 comments on commit d5dc1fb

Please sign in to comment.