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

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

Closed
andersk opened this issue Jul 26, 2024 · 1 comment · Fixed by #17588
Closed

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

andersk opened this issue Jul 26, 2024 · 1 comment · Fixed by #17588
Labels

Comments

@andersk
Copy link
Contributor

andersk commented Jul 26, 2024

dmypy crashes on import stripe, and I reduced the failure to the minimal test case below with no external dependencies. This is similar to

but it remains a problem on current master (e67decb) even after #17515 was marked fixed. This is a regression in v1.11.0, and git bisect shows it was introduced by 1072c78 (#17148, cc @JelleZijlstra).

test.py

from typing import TypedDict

class A(TypedDict):
    b: "B"

class B(TypedDict):
    c: "C"

class C(TypedDict):
    d: "D"

class D:
    pass
$ mypy --show-traceback --cache-fine-grained test.py
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.12.0+dev.e67decb91ea5aacbb1e126463b02d78ded680a90
Traceback (most recent call last):
  File "/tmp/venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/anders/python/mypy/mypy/__main__.py", line 15, in console_entry
    main()
  File "/home/anders/python/mypy/mypy/main.py", line 103, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/anders/python/mypy/mypy/main.py", line 187, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/anders/python/mypy/mypy/build.py", line 193, in build
    result = _build(
  File "/home/anders/python/mypy/mypy/build.py", line 268, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/anders/python/mypy/mypy/build.py", line 2950, in dispatch
    process_graph(graph, manager)
  File "/home/anders/python/mypy/mypy/build.py", line 3348, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/anders/python/mypy/mypy/build.py", line 3453, in process_stale_scc
    graph[id].finish_passes()
  File "/home/anders/python/mypy/mypy/build.py", line 2372, in finish_passes
    with self.wrap_context():
  File "/nix/store/z7xxy35k7620hs6fn6la5fg2lgklv72l-python3-3.12.4/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/home/anders/python/mypy/mypy/build.py", line 2069, in wrap_context
    yield
  File "/home/anders/python/mypy/mypy/build.py", line 2409, in finish_passes
    self.update_fine_grained_deps(self.manager.fg_deps)
  File "/home/anders/python/mypy/mypy/build.py", line 2467, in update_fine_grained_deps
    merge_dependencies(self.compute_fine_grained_deps(), deps)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/build.py", line 2455, in compute_fine_grained_deps
    return get_dependencies(
           ^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 187, in get_dependencies
    target.accept(visitor)
  File "/home/anders/python/mypy/mypy/nodes.py", line 372, in accept
    return visitor.visit_mypy_file(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 250, in visit_mypy_file
    super().visit_mypy_file(o)
  File "/home/anders/python/mypy/mypy/traverser.py", line 116, in visit_mypy_file
    d.accept(self)
  File "/home/anders/python/mypy/mypy/nodes.py", line 1183, in accept
    return visitor.visit_class_def(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 310, in visit_class_def
    super().visit_class_def(o)
  File "/home/anders/python/mypy/mypy/traverser.py", line 152, in visit_class_def
    o.defs.accept(self)
  File "/home/anders/python/mypy/mypy/nodes.py", line 1264, in accept
    return visitor.visit_block(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 429, in visit_block
    super().visit_block(o)
  File "/home/anders/python/mypy/mypy/traverser.py", line 120, in visit_block
    s.accept(self)
  File "/home/anders/python/mypy/mypy/nodes.py", line 1351, in accept
    return visitor.visit_assignment_stmt(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 490, in visit_assignment_stmt
    self.add_type_dependencies(o.type)
  File "/home/anders/python/mypy/mypy/server/deps.py", line 887, in add_type_dependencies
    for trigger in self.get_type_triggers(typ):
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 940, in get_type_triggers
    return get_type_triggers(typ, self.use_logical_deps())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/server/deps.py", line 947, in get_type_triggers
    return typ.accept(TypeTriggersVisitor(use_logical_deps, seen_aliases))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anders/python/mypy/mypy/types.py", line 2708, in accept
    assert isinstance(visitor, SyntheticTypeVisitor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 
test.py: : note: use --pdb to drop into pdb
@andersk andersk added the crash label Jul 26, 2024
andersk added a commit to andersk/mypy that referenced this issue Jul 26, 2024
andersk added a commit to andersk/mypy that referenced this issue Jul 26, 2024
Commit 1072c78 (python#17148) converted all
quoted types into RawExpressionType, which raised an AssertionError
when accepting a TypeTriggersVisitor.

Fixes python#17587.

Signed-off-by: Anders Kaseorg <[email protected]>
@andersk
Copy link
Contributor Author

andersk commented Jul 26, 2024

Is this the right fix or is something deeper going on?

--- a/mypy/types.py
+++ b/mypy/types.py
@@ -2705,6 +2705,8 @@ class RawExpressionType(ProperType):
         return self.base_type_name.replace("builtins.", "")
 
     def accept(self, visitor: TypeVisitor[T]) -> T:
+        if self.node is not None:
+            return self.node.accept(visitor)
         assert isinstance(visitor, SyntheticTypeVisitor)
         ret: T = visitor.visit_raw_expression_type(self)
         return ret

hauntsaninja pushed a commit that referenced this issue Jul 27, 2024
)

Commit 1072c78 (#17148) converted all
quoted types into `RawExpressionType`, which raised an `AssertionError`
when `accept`ing a `TypeTriggersVisitor`.

- Fixes #17574.
- Fixes #17587.

Signed-off-by: Anders Kaseorg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant