diff options
author | Damien George <damien@micropython.org> | 2024-10-01 10:26:27 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-10-16 15:03:30 +1100 |
commit | 1b89c503db690967d50699abe0bfa942f6f6b15e (patch) | |
tree | 5dbde19959d3f56328bf95dceff981e21ae28106 /tests/basics/class_descriptor.py | |
parent | 3fecab58a0bab6db736d24c0be7e78e04c651cb0 (diff) |
py/objtype: Don't delegate lookup of descriptor methods to __getattr__.
When descriptors are enabled, lookup of the `__get__`, `__set__` and
`__delete__` descriptor methods should not be delegated to `__getattr__`.
That follows CPython behaviour.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/basics/class_descriptor.py')
-rw-r--r-- | tests/basics/class_descriptor.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/basics/class_descriptor.py b/tests/basics/class_descriptor.py index 54f386230..83d316743 100644 --- a/tests/basics/class_descriptor.py +++ b/tests/basics/class_descriptor.py @@ -21,14 +21,41 @@ m = Main() try: m.__class__ except AttributeError: + # Target doesn't support __class__. print("SKIP") raise SystemExit r = m.Forward if 'Descriptor' in repr(r.__class__): + # Target doesn't support descriptors. print('SKIP') raise SystemExit +# Test assignment and deletion. + print(r) m.Forward = 'a' del m.Forward + +# Test that lookup of descriptors like __get__ are not passed into __getattr__. + + +class NonDescriptor: + def __getattr__(self, attr): + print("getattr", attr) + + +class TestClass: + non_descriptor = NonDescriptor() + + +print(isinstance(TestClass().non_descriptor, NonDescriptor)) + +t = TestClass() +t.non_descriptor = 123 +print(t.non_descriptor) + +try: + del TestClass().non_descriptor +except AttributeError: + print("AttributeError") |