mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix previous merge of objtype.rs.
Moved the tests to their more correct place of `tests/snippets/class.py`.
This commit is contained in:
1 parent
23e0467876
commit
6ea5d58f24
3 files changed
+50
-52
No files matched your search
@@ -207,3 +207,49 @@ assert B.__doc__ == "Docstring"
|
||||
# assert a == 3
|
||||
# A.b()
|
||||
# nested_scope()
|
||||
|
||||
|
||||
|
||||
# Multiple inheritance and mro tests.
|
||||
class A():
|
||||
def f(self):
|
||||
return 'a'
|
||||
|
||||
class B(A):
|
||||
def f(self):
|
||||
return 'b' + super().f()
|
||||
|
||||
class C(A):
|
||||
def f(self):
|
||||
return 'c' + super().f()
|
||||
|
||||
class D(B, C):
|
||||
def f(self):
|
||||
return 'd' + super().f()
|
||||
|
||||
assert D().f() == 'dbca', "Mro resolution using super failed."
|
||||
|
||||
|
||||
|
||||
class A():
|
||||
pass
|
||||
try:
|
||||
class B(A, A):
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
assert False, "Managed to create a class with duplicate base classes."
|
||||
|
||||
|
||||
class A():
|
||||
pass
|
||||
class B(A):
|
||||
pass
|
||||
try:
|
||||
class C(A, B):
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
assert False, "Managed to create a class without local type precedence."
|
||||
@@ -99,47 +99,3 @@ assert C.mro() == [C, B, A, BB, AA, object]
|
||||
|
||||
assert type(Exception.args).__name__ == 'getset_descriptor'
|
||||
assert type(None).__bool__(None) is False
|
||||
|
||||
|
||||
class A():
|
||||
def f(self):
|
||||
return 'a'
|
||||
|
||||
class B(A):
|
||||
def f(self):
|
||||
return 'b' + super().f()
|
||||
|
||||
class C(A):
|
||||
def f(self):
|
||||
return 'c' + super().f()
|
||||
|
||||
class D(B, C):
|
||||
def f(self):
|
||||
return 'd' + super().f()
|
||||
|
||||
assert D().f() == 'dbca', "Mro resolution using super failed."
|
||||
|
||||
|
||||
|
||||
class A():
|
||||
pass
|
||||
try:
|
||||
class B(A, A):
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
assert False, "Managed to create a class with duplicate base classes."
|
||||
|
||||
|
||||
class A():
|
||||
pass
|
||||
class B(A):
|
||||
pass
|
||||
try:
|
||||
class C(A, B):
|
||||
pass
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
assert False, "Managed to create a class without local type precedence."
|
||||
@@ -291,16 +291,14 @@ impl PyClassRef {
|
||||
}
|
||||
}
|
||||
|
||||
let typ = match new(metatype, name.as_str(), base.clone(), bases, attributes) {
|
||||
match new(metatype, name.as_str(), base.clone(), bases, attributes) {
|
||||
Ok(typ) => {
|
||||
typ.slots.borrow_mut().flags = base.slots.borrow().flags;
|
||||
vm.ctx.add_tp_new_wrapper(&typ);
|
||||
Ok(typ.into())
|
||||
}
|
||||
Err(string) => Err(vm.new_type_error(string)),
|
||||
}?;
|
||||
typ.slots.borrow_mut().flags = base.slots.borrow().flags;
|
||||
vm.ctx.add_tp_new_wrapper(&typ);
|
||||
Ok(typ.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[pyslot]
|
||||
@@ -437,9 +435,7 @@ impl PyClassRef {
|
||||
}
|
||||
}
|
||||
|
||||
fn take_next_base(mut bases: Vec<Vec<PyClassRef>>) -> Option<(PyClassRef, Vec<Vec<PyClassRef>>)> {
|
||||
let mut next = None;
|
||||
|
||||
fn take_next_base(mut bases: Vec<Vec<PyClassRef>>) -> (Option<PyClassRef>, Vec<Vec<PyClassRef>>) {
|
||||
bases = bases.into_iter().filter(|x| !x.is_empty()).collect();
|
||||
|
||||
for base in &bases {
|
||||
|
||||
Reference in new issue
Block a user