Merge pull request #732 from palaviv/super-classmethod

Support classmethod super
This commit is contained in:
coolreader18 authored and GitHub committed 2019-03-23 14:17:06 -05:00
commit cecc2e1835
2 files changed
+15

No files matched your search

+10
View File
@@ -64,6 +64,10 @@ class B():
def test1(self):
return 200
@classmethod
def test3(cls):
return 300
class C(A,B):
def test(self):
return super().test()
@@ -71,9 +75,15 @@ class C(A,B):
def test1(self):
return super().test1()
@classmethod
def test3(cls):
return super().test3()
c = C()
assert c.test() == 100
assert c.test1() == 200
assert c.test3() == 300
assert C.test3() == 300
class Me():
+5
View File
@@ -8,6 +8,7 @@ https://github.com/python/cpython/blob/50b48572d9a90c5bb36e2bef6179548ea927a35a/
use crate::frame::NameProtocol;
use crate::function::{OptionalArg, PyFuncArgs};
use crate::obj::objfunction::PyMethod;
use crate::obj::objstr;
use crate::obj::objtype::{PyClass, PyClassRef};
use crate::pyobject::{
@@ -72,6 +73,10 @@ fn super_getattribute(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
Some(PyClass { ref mro, .. }) => {
for class in mro {
if let Ok(item) = vm.get_attribute(class.as_object().clone(), name_str.clone()) {
if item.payload_is::<PyMethod>() {
// This is a classmethod
return Ok(item);
}
return Ok(vm.ctx.new_bound_method(item, inst.clone()));
}
}