Skip to content

Improve the error message for assert and AssertionError by adding location information #105724

Open
@sobolevn

Description

@sobolevn

Feature or enhancement

Right now assert generate errors that are hard to read, mostly because they lack context.
Example:

>>> assert 1 == 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

Pitch

Let's make them better:

>>> assert 1 == 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    assert 1 == 0
           ^^^^^^
AssertionError

This is a good starting point.

Later this can be enhanced to use more context.

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions