From 15b7ff0c68c6ed2c0672d9017180c08e1baee7f3 Mon Sep 17 00:00:00 2001 From: David Marques Date: Sat, 7 May 2022 16:54:59 +0200 Subject: [PATCH 1/3] Added self and self_class to pysuper --- vm/src/builtins/super.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vm/src/builtins/super.rs b/vm/src/builtins/super.rs index a8bb7e1043..bdcee6eb70 100644 --- a/vm/src/builtins/super.rs +++ b/vm/src/builtins/super.rs @@ -114,6 +114,15 @@ impl PySuper { self.typ.clone() } + #[pyproperty(magic)] + fn selfclass(&self) -> Option { + Some(self.obj.as_ref()?.1.clone()) + } + + fn __self__(&self) -> Option { + Some(self.obj.as_ref()?.0.clone()) + } + #[pymethod(magic)] fn repr(&self) -> String { let typname = &self.typ.name(); From 00955f2cf16af5d35163f8053d72c2c6ff864bb8 Mon Sep 17 00:00:00 2001 From: David Marques Date: Sat, 7 May 2022 17:22:20 +0200 Subject: [PATCH 2/3] Added test for the super methods --- extra_tests/snippets/builtin_super.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 extra_tests/snippets/builtin_super.py diff --git a/extra_tests/snippets/builtin_super.py b/extra_tests/snippets/builtin_super.py new file mode 100644 index 0000000000..ab835b20d4 --- /dev/null +++ b/extra_tests/snippets/builtin_super.py @@ -0,0 +1,5 @@ +def test_super_list(): + 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 From 2a4cc899454f2fc450f13567ed5074441cd2791f Mon Sep 17 00:00:00 2001 From: David Marques Date: Sat, 7 May 2022 20:10:41 +0200 Subject: [PATCH 3/3] Added extra tests --- extra_tests/snippets/builtin_super.py | 23 ++++++++++++++++++----- vm/src/builtins/super.rs | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/extra_tests/snippets/builtin_super.py b/extra_tests/snippets/builtin_super.py index ab835b20d4..d787a5b6a9 100644 --- a/extra_tests/snippets/builtin_super.py +++ b/extra_tests/snippets/builtin_super.py @@ -1,5 +1,18 @@ -def test_super_list(): - 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 +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 bdcee6eb70..fb566f4777 100644 --- a/vm/src/builtins/super.rs +++ b/vm/src/builtins/super.rs @@ -115,10 +115,11 @@ impl PySuper { } #[pyproperty(magic)] - fn selfclass(&self) -> Option { + fn self_class(&self) -> Option { Some(self.obj.as_ref()?.1.clone()) } + #[pyproperty] fn __self__(&self) -> Option { Some(self.obj.as_ref()?.0.clone()) }