Skip to content

Commit 8792ff1

Browse files
authoredJul 29, 2023
Raise RuntimeError with better error messages (#15778)
While working on #15776 I've noticed that some `RuntimeError` do not have enough metadata to understand what is going on. CI: https://github.com/python/mypy/actions/runs/5700479199/job/15450345887 This PR adds more context to error messages.
1 parent 6040b23 commit 8792ff1

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed
 

‎mypy/erasetype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def visit_erased_type(self, t: ErasedType) -> ProperType:
7171

7272
def visit_partial_type(self, t: PartialType) -> ProperType:
7373
# Should not get here.
74-
raise RuntimeError()
74+
raise RuntimeError("Cannot erase partial types")
7575

7676
def visit_deleted_type(self, t: DeletedType) -> ProperType:
7777
return t

‎mypy/nodes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def str_with_options(self, options: Options) -> str:
203203
return ans
204204

205205
def accept(self, visitor: NodeVisitor[T]) -> T:
206-
raise RuntimeError("Not implemented")
206+
raise RuntimeError("Not implemented", type(self))
207207

208208

209209
@trait
@@ -213,7 +213,7 @@ class Statement(Node):
213213
__slots__ = ()
214214

215215
def accept(self, visitor: StatementVisitor[T]) -> T:
216-
raise RuntimeError("Not implemented")
216+
raise RuntimeError("Not implemented", type(self))
217217

218218

219219
@trait
@@ -223,7 +223,7 @@ class Expression(Node):
223223
__slots__ = ()
224224

225225
def accept(self, visitor: ExpressionVisitor[T]) -> T:
226-
raise RuntimeError("Not implemented")
226+
raise RuntimeError("Not implemented", type(self))
227227

228228

229229
class FakeExpression(Expression):

‎mypy/patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Pattern(Node):
1919
__slots__ = ()
2020

2121
def accept(self, visitor: PatternVisitor[T]) -> T:
22-
raise RuntimeError("Not implemented")
22+
raise RuntimeError("Not implemented", type(self))
2323

2424

2525
class AsPattern(Pattern):

‎mypy/server/astmerge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ def visit_overloaded(self, t: Overloaded) -> None:
467467

468468
def visit_erased_type(self, t: ErasedType) -> None:
469469
# This type should exist only temporarily during type inference
470-
raise RuntimeError
470+
raise RuntimeError("Cannot handle erased type")
471471

472472
def visit_deleted_type(self, typ: DeletedType) -> None:
473473
pass
474474

475475
def visit_partial_type(self, typ: PartialType) -> None:
476-
raise RuntimeError
476+
raise RuntimeError("Cannot handle partial type")
477477

478478
def visit_tuple_type(self, typ: TupleType) -> None:
479479
for item in typ.items:

‎mypy/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def can_be_false_default(self) -> bool:
260260
return True
261261

262262
def accept(self, visitor: TypeVisitor[T]) -> T:
263-
raise RuntimeError("Not implemented")
263+
raise RuntimeError("Not implemented", type(self))
264264

265265
def __repr__(self) -> str:
266266
return self.accept(TypeStrVisitor(options=Options()))

0 commit comments

Comments
 (0)
Please sign in to comment.