diff --git a/extra_tests/snippets/builtin_super.py b/extra_tests/snippets/builtin_super.py new file mode 100644 index 0000000000..d787a5b6a9 --- /dev/null +++ b/extra_tests/snippets/builtin_super.py @@ -0,0 +1,18 @@ +test_super_list = super(list) +assert test_super_list.__self__ is None +assert test_super_list.__self_class__ is None +assert test_super_list.__thisclass__ == list + + +class testA: + a = 1 + + +class testB(testA): + b = 1 + + +superB = super(testB) +assert superB.__thisclass__ == testB +assert superB.__self_class__ is None +assert superB.__self__ is None diff --git a/vm/src/builtins/super.rs b/vm/src/builtins/super.rs index a8bb7e1043..fb566f4777 100644 --- a/vm/src/builtins/super.rs +++ b/vm/src/builtins/super.rs @@ -114,6 +114,16 @@ impl PySuper { self.typ.clone() } + #[pyproperty(magic)] + fn self_class(&self) -> Option { + Some(self.obj.as_ref()?.1.clone()) + } + + #[pyproperty] + fn __self__(&self) -> Option { + Some(self.obj.as_ref()?.0.clone()) + } + #[pymethod(magic)] fn repr(&self) -> String { let typname = &self.typ.name();