From 5aff28ba70a94506ce57d1b4e6ca7b186a0e7cdc Mon Sep 17 00:00:00 2001 From: Moreal Date: Sun, 14 Apr 2024 12:01:58 +0900 Subject: [PATCH 1/3] Add testcase for `__ne__` method --- Lib/test/test_builtin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 9e13fbb2c8..e096776051 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -610,6 +610,11 @@ def __dir__(self): # test that object has a __dir__() self.assertEqual(sorted([].__dir__()), dir([])) + def test___ne__(self): + self.assertFalse(None.__ne__(None)) + self.assertIs(None.__ne__(0), NotImplemented) + self.assertIs(None.__ne__("abc"), NotImplemented) + def test_divmod(self): self.assertEqual(divmod(12, 7), (1, 5)) self.assertEqual(divmod(-12, 7), (-2, 2)) From 3ebe062bf4938cfdb5c6e10ada2f56596c67e0ab Mon Sep 17 00:00:00 2001 From: Moreal Date: Sun, 14 Apr 2024 12:07:52 +0900 Subject: [PATCH 2/3] Fix `None.__ne__` bug --- extra_tests/snippets/builtin_none.py | 2 +- vm/src/builtins/singletons.rs | 29 +++------------------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/extra_tests/snippets/builtin_none.py b/extra_tests/snippets/builtin_none.py index c8a07f518d..d605f1d742 100644 --- a/extra_tests/snippets/builtin_none.py +++ b/extra_tests/snippets/builtin_none.py @@ -22,4 +22,4 @@ def none2(): assert None.__eq__(3) is NotImplemented assert None.__ne__(3) is NotImplemented assert None.__eq__(None) is True -assert None.__ne__(None) is NotImplemented +assert None.__ne__(None) is False diff --git a/vm/src/builtins/singletons.rs b/vm/src/builtins/singletons.rs index d4487b586d..65b171a262 100644 --- a/vm/src/builtins/singletons.rs +++ b/vm/src/builtins/singletons.rs @@ -2,10 +2,9 @@ use super::{PyStrRef, PyType, PyTypeRef}; use crate::{ class::PyClassImpl, convert::ToPyObject, - function::{PyArithmeticValue, PyComparisonValue}, protocol::PyNumberMethods, - types::{AsNumber, Comparable, Constructor, PyComparisonOp, Representable}, - Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, + types::{AsNumber, Constructor, Representable}, + Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "NoneType")] @@ -43,7 +42,7 @@ impl Constructor for PyNone { } } -#[pyclass(with(Constructor, Comparable, AsNumber, Representable))] +#[pyclass(with(Constructor, AsNumber, Representable))] impl PyNone { #[pymethod(magic)] fn bool(&self) -> bool { @@ -73,28 +72,6 @@ impl AsNumber for PyNone { } } -impl Comparable for PyNone { - fn cmp( - _zelf: &Py, - other: &PyObject, - op: PyComparisonOp, - vm: &VirtualMachine, - ) -> PyResult { - let value = match op { - PyComparisonOp::Eq => { - if vm.is_none(other) { - PyArithmeticValue::Implemented(true) - } else { - PyArithmeticValue::NotImplemented - } - } - _ => PyComparisonValue::NotImplemented, - }; - - Ok(value) - } -} - #[pyclass(module = false, name = "NotImplementedType")] #[derive(Debug)] pub struct PyNotImplemented; From c01ad026af9ec50cab844f95c582436441edd965 Mon Sep 17 00:00:00 2001 From: Moreal Date: Sun, 14 Apr 2024 12:22:23 +0900 Subject: [PATCH 3/3] Bump CPython version to 3.12.3 in CI --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 553fa6b1ef..0c80cc894e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -105,7 +105,7 @@ env: test_weakref test_yield_from # Python version targeted by the CI. - PYTHON_VERSION: "3.12.0" + PYTHON_VERSION: "3.12.3" jobs: rust_tests: @@ -140,7 +140,7 @@ jobs: - name: run rust tests run: cargo test --workspace --exclude rustpython_wasm --verbose --features threading ${{ env.CARGO_ARGS }} - if: runner.os != 'macOS' + if: runner.os != 'macOS' # temp skip ssl linking for Mac to avoid CI failure - name: run rust tests (MacOS no ssl) run: cargo test --workspace --exclude rustpython_wasm --verbose --no-default-features --features threading,stdlib,zlib,importlib,encodings,jit