Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError with TypedDict and --cache-fine-grained in v1.11.0 #17515

Closed
svalentin opened this issue Jul 10, 2024 · 4 comments
Closed

AssertionError with TypedDict and --cache-fine-grained in v1.11.0 #17515

svalentin opened this issue Jul 10, 2024 · 4 comments

Comments

@svalentin
Copy link
Collaborator

svalentin commented Jul 10, 2024

Crash Report

Make a file with:

from typing import TypedDict

class SomeEntry(TypedDict):
    somefield: "set[str]"

Running mypy with --cache-fine-grained causes assertion error.

The assertion error is no longer raised if either of these is done:

  • using from __future__ import annotations and changing the types from strings to actual types.
  • removing --cache-fine-grained.
  • using mypy v1.10.1.

Repro and Traceback

$ python3 -m mypy --strict --cache-fine-grained --show-traceback ~/src/x-play
/home/svalentin/src/x-play/test.py: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.11.0+dev.d8c67c36d6ecf964dd283de3acffc59d80c8b1fd
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/svalentin/src/mypy/mypy/__main__.py", line 37, in <module>
    console_entry()
  File "/home/svalentin/src/mypy/mypy/__main__.py", line 15, in console_entry
    main()
  File "/home/svalentin/src/mypy/mypy/main.py", line 103, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/svalentin/src/mypy/mypy/main.py", line 187, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/svalentin/src/mypy/mypy/build.py", line 193, in build
    result = _build(
  File "/home/svalentin/src/mypy/mypy/build.py", line 268, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/svalentin/src/mypy/mypy/build.py", line 2944, in dispatch
    return dispatch(sources, manager, stdout)
  File "/home/svalentin/src/mypy/mypy/build.py", line 2950, in dispatch
    process_graph(graph, manager)
  File "/home/svalentin/src/mypy/mypy/build.py", line 3348, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/svalentin/src/mypy/mypy/build.py", line 3453, in process_stale_scc
    graph[id].finish_passes()
  File "/home/svalentin/src/mypy/mypy/build.py", line 2372, in finish_passes
    with self.wrap_context():
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/svalentin/src/mypy/mypy/build.py", line 2069, in wrap_context
    yield
  File "/home/svalentin/src/mypy/mypy/build.py", line 2409, in finish_passes
    self.update_fine_grained_deps(self.manager.fg_deps)
  File "/home/svalentin/src/mypy/mypy/build.py", line 2467, in update_fine_grained_deps
    merge_dependencies(self.compute_fine_grained_deps(), deps)
  File "/home/svalentin/src/mypy/mypy/build.py", line 2455, in compute_fine_grained_deps
    return get_dependencies(
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 187, in get_dependencies
    target.accept(visitor)
  File "/home/svalentin/src/mypy/mypy/nodes.py", line 372, in accept
    return visitor.visit_mypy_file(self)
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 250, in visit_mypy_file
    super().visit_mypy_file(o)
  File "/home/svalentin/src/mypy/mypy/traverser.py", line 116, in visit_mypy_file
    d.accept(self)
  File "/home/svalentin/src/mypy/mypy/nodes.py", line 1183, in accept
    return visitor.visit_class_def(self)
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 310, in visit_class_def
    super().visit_class_def(o)
  File "/home/svalentin/src/mypy/mypy/traverser.py", line 152, in visit_class_def
    o.defs.accept(self)
  File "/home/svalentin/src/mypy/mypy/nodes.py", line 1264, in accept
    return visitor.visit_block(self)
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 429, in visit_block
    super().visit_block(o)
  File "/home/svalentin/src/mypy/mypy/traverser.py", line 120, in visit_block
    s.accept(self)
  File "/home/svalentin/src/mypy/mypy/nodes.py", line 1351, in accept
    return visitor.visit_assignment_stmt(self)
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 490, in visit_assignment_stmt
    self.add_type_dependencies(o.type)
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 887, in add_type_dependencies
    for trigger in self.get_type_triggers(typ):
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 940, in get_type_triggers
    return get_type_triggers(typ, self.use_logical_deps())
  File "/home/svalentin/src/mypy/mypy/server/deps.py", line 947, in get_type_triggers
    return typ.accept(TypeTriggersVisitor(use_logical_deps, seen_aliases))
  File "/home/svalentin/src/mypy/mypy/types.py", line 2703, in accept
    assert isinstance(visitor, SyntheticTypeVisitor)
AssertionError:
/home/svalentin/src/x-play/test.py: : note: use --pdb to drop into pdb

Your Environment
Ubuntu 22.04.4 LTS (Jammy Jellyfish)

$ python3 --version
Python 3.10.12
$ python3 -m mypy --version
mypy 1.11.0+dev.d8c67c36d6ecf964dd283de3acffc59d80c8b1fd (compiled: no)
@svalentin svalentin changed the title AssertionError with TypedDict in v1.11.0 AssertionError with TypedDict and --cache-fine-grained in v1.11.0 Jul 10, 2024
@hauntsaninja
Copy link
Collaborator

Writing your example to test.py and adding # flags: --cache-fine-grained --strict then running mypy_primer -p test.py --bisect --debug --old 'v1.10.0' bisects this to #17148 cc @JelleZijlstra

@JelleZijlstra
Copy link
Member

Oops. Will take a look though I don't know too much about the cache.

@JelleZijlstra JelleZijlstra self-assigned this Jul 10, 2024
@ilevkivskyi
Copy link
Member

This is already fixed on master.

@andersk
Copy link
Contributor

andersk commented Jul 26, 2024

This test case was fixed by e5b3b56 (#17495), but I have another test case that still reproduces the same symptom on current master:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants