alexmojaki / alexmojaki/executing

Finer-grained errors, ala PEP 657?

未关闭
#90 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
401
派生
38
PR 合并指标
30 天内没有已合并 PR

描述

[PEP 657](https://peps.python.org/pep-0657/) added "fine-grained errors" which are similar to executing's AST-level `text_range`. But the default python traceback printing goes further, employing _two_ types of error markers, `^` and `~`. The latter is a "secondary" marker used for further detailed refinement for exceptions involving binary and indexing operators. Example:

File fge.py
```python
x={}; x['a']={}; x['a']['b'] = None
x['a']['b']['c']['d'] = 1
```

Produces:

```python
% python3.12 fge.py
Traceback (most recent call last):
File "/Users/jdsmith/code/python/scraps/fge.py", line 2, in
x['a']['b']['c']['d'] = 1
~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
```

while executing (here in iPython), shows:

image

One way to support this secondary refinement in a backwards-compatible way would be with an additional method `text_range_secondary` that computes the sub-region within `text_range` (if any) that could be highlighted distinctly.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。