Merge pull request #2683 from RustPython/method-self-getter

Add method.__self__ attribute
This commit is contained in:
Noah
2021-06-02 22:12:09 -05:00
committed by GitHub
4 changed files with 5 additions and 6 deletions

View File

@@ -887,8 +887,6 @@ class TestCopy(unittest.TestCase):
del d
self.assertEqual(len(v), 1)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_deepcopy_bound_method(self):
class Foo(object):
def m(self):

View File

@@ -543,8 +543,6 @@ class TestPartialMethod(unittest.TestCase):
self.assertEqual(self.A.over_partial(self.a, 5, d=8), ((self.a, 7, 5), {'c': 6, 'd': 8}))
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_bound_method_introspection(self):
obj = self.a
self.assertIs(obj.both.__self__, obj)

View File

@@ -1325,8 +1325,6 @@ class TestDetectEncoding(TestCase):
self.assertEqual(fp.encoding, 'utf-8-sig')
self.assertEqual(fp.mode, 'r')
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_filename_in_exception(self):
# When possible, include the file name in the exception.
path = 'some_file_path'

View File

@@ -473,6 +473,11 @@ impl PyBoundMethod {
self.function.clone()
}
#[pyproperty(name = "__self__")]
fn get_self(&self) -> PyObjectRef {
self.object.clone()
}
#[pyproperty(magic)]
fn module(&self, vm: &VirtualMachine) -> Option<PyObjectRef> {
vm.get_attribute(self.function.clone(), "__module__").ok()