python - PyCharm 在不应该的断点处停止

标签 python debugging pycharm breakpoints

我在 PyCharm 中遇到这种行为 Build #PY-222.4345.23在 macOS 蒙特利 12.6.1 ,这发生在 python 3.10 中和3.11 .

def example(i):
    match i % 4:
        case 0:
            if i > 10:
                return 0
        case 1:
            if i > 10:
                return 1
        case 2:
            if i > 10:
                print(f'{i}, {i > 10}')
                return 2
        case 3:
            if i > 10:
                return 3


if __name__ == '__main__':
    print(example(2))

在两个 python 版本中,调试器都会在第三个返回语句处停止(意外, block 应该无法访问),但实际上不会返回任何给定输入的预期行为 2

python 3.11(1 个断点来重现)

enter image description here

python 3.10(要重现的 2 个断点)

enter image description here

如果开关和外壳更换为if/elif block ,永远不会达到相同的断点,这正是我期望的 switch block 的行为。

def example(i):
    j = i % 4
    if j == 0:
        if i > 10:
            return 0
    elif j == 1:
        if i > 10:
            return 1
    elif j == 2:
        if i > 10:
            print(f'{i}, {i > 10}')
            return 2
    elif j == 3:
        if i > 10:
            return 3


if __name__ == '__main__':
    print(example(2))

最佳答案

IDE 错误。我已在 PyCharm 的问题跟踪器中提交了一张票证 - https://youtrack.jetbrains.com/issue/PY-57125/PyCharm-stops-on-non-hit-breakpoint-inside-pattern-matching-block

关于python - PyCharm 在不应该的断点处停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74261550/

相关文章:

pycharm - 安装了 IdeaVIM 的 Pycharm 中的参数提示

android - 我如何设置Android :Debuggable false

javascript - 在 Release模式下调试 Visual Studio Web 应用程序

python - Pycharm: "No Python interpreter configured for the project"每次

python - lxml 未安装在 pycharm ide 中

c++ - 列表迭代器不兼容断言失败

python - 使用 etree 从 xml 标签解析 namespace

Python从csv文件中提取唯一记录

Python - 将包含 tkinter 小部件的框架传递到类中

python - 为什么 scipy.io.wavfile.read 不返回元组?