From b3a102ef31f63a8a8ba32c8dbe160ddef3c43054 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 26 Jul 2024 16:08:45 -0700 Subject: [PATCH] Fix `RawExpressionType.accept` crash with `--cache-fine-grained` (#17588) Commit 1072c78ad375b7f0511549287f54432050396717 (#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 --- mypy/types.py | 2 ++ test-data/unit/check-typeddict.test | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/mypy/types.py b/mypy/types.py index ada45112ebf5..3dce98be6cf0 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -2703,6 +2703,8 @@ def simple_name(self) -> str: 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 diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index d35ec8ddd80e..a6a89f14309f 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -1442,6 +1442,18 @@ reveal_type(x) # N: Revealed type is "TypedDict('__main__.X', {'a': TypedDict('_ reveal_type(x['a']['b']) # N: Revealed type is "builtins.int" [builtins fixtures/dict.pyi] +[case testTypedDictForwardReferenceCacheFineGrained] +# flags: --cache-fine-grained +from mypy_extensions import TypedDict +class A(TypedDict): + b: "B" +class B(TypedDict): + c: "C" +class C(TypedDict): + d: "D" +class D: + pass + [case testSelfRecursiveTypedDictInheriting] from mypy_extensions import TypedDict