From 9ede5fde7513752d480809aba659f0eb5f41ccf5 Mon Sep 17 00:00:00 2001 From: minhrongcon2000 Date: Sat, 18 Mar 2023 22:38:57 +0700 Subject: [PATCH 1/2] Fix test_bool test_subclass --- Lib/test/test_bool.py | 3 --- vm/src/builtins/int.rs | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 6da00aacd6..cc547fbfde 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -6,9 +6,6 @@ import os class BoolTest(unittest.TestCase): - - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_subclass(self): try: class C(bool): diff --git a/vm/src/builtins/int.rs b/vm/src/builtins/int.rs index 46b81de56b..1e5f868cd8 100644 --- a/vm/src/builtins/int.rs +++ b/vm/src/builtins/int.rs @@ -1,4 +1,4 @@ -use super::{float, PyByteArray, PyBytes, PyStr, PyType, PyTypeRef}; +use super::{float, PyByteArray, PyBytes, PyStr, PyType, PyTypeRef, PyBool}; use crate::{ builtins::PyStrRef, bytesinner::PyBytesInner, @@ -213,6 +213,9 @@ impl Constructor for PyInt { type Args = IntOptions; fn py_new(cls: PyTypeRef, options: Self::Args, vm: &VirtualMachine) -> PyResult { + if cls.is(PyBool::class(vm)) { + return Err(vm.new_type_error("int.__new__(bool) is not safe, use bool.__new__()".to_owned())); + } let value = if let OptionalArg::Present(val) = options.val_options { if let OptionalArg::Present(base) = options.base { let base = base From 20f4fb2d92cc373be8715dcf89eea74a636576a9 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 21 Mar 2023 15:07:00 +0900 Subject: [PATCH 2/2] fix lint --- vm/src/builtins/int.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vm/src/builtins/int.rs b/vm/src/builtins/int.rs index 1e5f868cd8..1db61d5f08 100644 --- a/vm/src/builtins/int.rs +++ b/vm/src/builtins/int.rs @@ -1,4 +1,4 @@ -use super::{float, PyByteArray, PyBytes, PyStr, PyType, PyTypeRef, PyBool}; +use super::{float, PyBool, PyByteArray, PyBytes, PyStr, PyType, PyTypeRef}; use crate::{ builtins::PyStrRef, bytesinner::PyBytesInner, @@ -214,7 +214,9 @@ impl Constructor for PyInt { fn py_new(cls: PyTypeRef, options: Self::Args, vm: &VirtualMachine) -> PyResult { if cls.is(PyBool::class(vm)) { - return Err(vm.new_type_error("int.__new__(bool) is not safe, use bool.__new__()".to_owned())); + return Err( + vm.new_type_error("int.__new__(bool) is not safe, use bool.__new__()".to_owned()) + ); } let value = if let OptionalArg::Present(val) = options.val_options { if let OptionalArg::Present(base) = options.base {