Skip to content

Commit

Permalink
Raise RuntimeError with better error messages (#15778)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sobolevn authored Jul 29, 2023
1 parent 6040b23 commit 8792ff1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def visit_erased_type(self, t: ErasedType) -> ProperType:

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

def visit_deleted_type(self, t: DeletedType) -> ProperType:
return t
Expand Down
6 changes: 3 additions & 3 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def str_with_options(self, options: Options) -> str:
return ans

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


@trait
Expand All @@ -213,7 +213,7 @@ class Statement(Node):
__slots__ = ()

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


@trait
Expand All @@ -223,7 +223,7 @@ class Expression(Node):
__slots__ = ()

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


class FakeExpression(Expression):
Expand Down
2 changes: 1 addition & 1 deletion mypy/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Pattern(Node):
__slots__ = ()

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


class AsPattern(Pattern):
Expand Down
4 changes: 2 additions & 2 deletions mypy/server/astmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ def visit_overloaded(self, t: Overloaded) -> None:

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

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

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

def visit_tuple_type(self, typ: TupleType) -> None:
for item in typ.items:
Expand Down
2 changes: 1 addition & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def can_be_false_default(self) -> bool:
return True

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

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

0 comments on commit 8792ff1

Please sign in to comment.