← 输入框|github.com|刷新
Skip to content

Boolean methods cause interpreter panic when presented with the wrong type #5460

Closed

Description

@Masterchef365

Summary

You can cause the latest version of the interpreter (01f7536) to panic with:

thread 'main' panicked at [...]rustpython-vm/src/builtins/bool.rs:212:28:
called `Option::unwrap()` on a `None` value

By running the following (invalid) code:

x = min # Some type which isn't a boolean
x |= True # Perform a boolean operation

Expected

I was hoping for an exception to be thrown, which I could possibly catch! Python 3 does this.

Actual

Panics, see above

Python Documentation

TypeError exception

Activity

  1. theshubhamp commented on Dec 26, 2024

    @theshubhamp
    Contributor

    Looks like the or, and & xor operators implemented in bool builtin were missing type check to int.

    Sent a PR including tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions