mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Ensure __new__ entries in class __dict__ are staticmethods (#6659)
* Initial plan * Wrap __new__ methods as staticmethods in type dicts Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com> * Unmark passing enum test Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
This commit is contained in:
1
Lib/test/test_enum.py
vendored
1
Lib/test/test_enum.py
vendored
@@ -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:
|
||||
|
||||
@@ -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(_)) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user