diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 8f4b39b4d..b9d9cf33e 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -5208,7 +5208,6 @@ class TestStdLib(unittest.TestCase): ]), ) - @unittest.expectedFailure # TODO: RUSTPYTHON; len is often/always > 256 def test_test_simple_enum(self): @_simple_enum(Enum) class SimpleColor: diff --git a/crates/vm/src/builtins/type.rs b/crates/vm/src/builtins/type.rs index 8660d1f2e..fed9af976 100644 --- a/crates/vm/src/builtins/type.rs +++ b/crates/vm/src/builtins/type.rs @@ -1,6 +1,6 @@ use super::{ - PyClassMethod, PyDictRef, PyList, PyStr, PyStrInterned, PyStrRef, PyTupleRef, PyWeak, - mappingproxy::PyMappingProxy, object, union_, + PyClassMethod, PyDictRef, PyList, PyStaticMethod, PyStr, PyStrInterned, PyStrRef, PyTupleRef, + PyWeak, mappingproxy::PyMappingProxy, object, union_, }; use crate::{ AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, @@ -1166,6 +1166,12 @@ impl Constructor for PyType { *f = PyClassMethod::from(f.clone()).into_pyobject(vm); } + if let Some(f) = attributes.get_mut(identifier!(vm, __new__)) + && f.class().is(vm.ctx.types.function_type) + { + *f = PyStaticMethod::from(f.clone()).into_pyobject(vm); + } + if let Some(current_frame) = vm.current_frame() { let entry = attributes.entry(identifier!(vm, __module__)); if matches!(entry, Entry::Vacant(_)) { diff --git a/extra_tests/snippets/builtin_type.py b/extra_tests/snippets/builtin_type.py index 67269e694..8cb0a09a2 100644 --- a/extra_tests/snippets/builtin_type.py +++ b/extra_tests/snippets/builtin_type.py @@ -584,6 +584,7 @@ assert ClassWithNew.__new__.__qualname__ == "ClassWithNew.__new__" assert ClassWithNew().__new__.__qualname__ == "ClassWithNew.__new__" assert ClassWithNew.__new__.__name__ == "__new__" assert ClassWithNew().__new__.__name__ == "__new__" +assert isinstance(ClassWithNew.__dict__.get("__new__"), staticmethod) assert ClassWithNew.N.__new__.__qualname__ == "ClassWithNew.N.__new__" assert ClassWithNew().N.__new__.__qualname__ == "ClassWithNew.N.__new__" @@ -593,6 +594,7 @@ assert ClassWithNew.N().__new__.__qualname__ == "ClassWithNew.N.__new__" assert ClassWithNew().N().__new__.__qualname__ == "ClassWithNew.N.__new__" assert ClassWithNew.N().__new__.__name__ == "__new__" assert ClassWithNew().N().__new__.__name__ == "__new__" +assert isinstance(ClassWithNew.N.__dict__.get("__new__"), staticmethod) # Regression to: