spylang/spy

Redshift should raise only StaticErrors

开放

#410 创建于 2026年2月28日

 (0 条评论) (0 个反应) (0 位负责人)Python (60 个派生)auto 404
help wanted

仓库指标

星标
 (803 个星标)
PR 合并指标
 (平均合并 11天 20小时) (30 天内合并 22 个 PR)

描述

The following code raises an exception during redshift, but it shouldn't:

def main() -> None:
    if False:
        1 / 0
❯ spy rs /tmp/t.spy 
Static error during redshift:
Traceback (most recent call last):
  * [redshift] t::main at /tmp/t.spy:3
  |         1 / 0
  |         |___|

ZeroDivisionError: division by zero

On the other hand, this code should continue to raise TypeError eagarly during redshift:

def main() -> None:
    if False:
        1 + "hello"

The difference between the two cases is that TypeError is a subclass of StaticError, while ZeroDivisionError is not.

If a non-StaticError is raised during redshift, it should be turned into the equivalent raise stmt. In other words, non-StaticError should always behave as if the error mode is set to lazy.

The piece of code responsible for that is here: https://github.com/spylang/spy/blob/3eafa094be3781e54e1e0852c644b6ff94233c27/spy/doppler.py#L139-L149

贡献者指南