|
1 | 1 | import unittest |
2 | 2 | from unittest.mock import patch |
3 | 3 | import builtins |
| 4 | +import types |
4 | 5 | import rlcompleter |
5 | 6 | from test.support import MISSING_C_DOCSTRINGS |
6 | 7 |
|
@@ -135,6 +136,49 @@ def bar(self): |
135 | 136 | self.assertEqual(completer.complete('f.b', 0), 'f.bar') |
136 | 137 | self.assertFalse(f.property_called) |
137 | 138 |
|
| 139 | + def test_released_memoryview_completion_works(self): |
| 140 | + mv = memoryview(b"abc") |
| 141 | + mv.release() |
| 142 | + |
| 143 | + self.assertIsInstance(type(mv).shape, types.GetSetDescriptorType) |
| 144 | + self.assertIsInstance(type(mv).strides, types.GetSetDescriptorType) |
| 145 | + |
| 146 | + completer = rlcompleter.Completer(dict(mv=mv)) |
| 147 | + matches = completer.attr_matches('mv.') |
| 148 | + |
| 149 | + # These are getset descriptors on memoryview and should be completed |
| 150 | + # without evaluating the released-memoryview getters. |
| 151 | + self.assertIn('mv.shape', matches) |
| 152 | + self.assertIn('mv.strides', matches) |
| 153 | + |
| 154 | + def test_member_descriptor_not_evaluated(self): |
| 155 | + class Foo: |
| 156 | + __slots__ = ("boom",) |
| 157 | + |
| 158 | + def __getattribute__(self, name): |
| 159 | + if name == "boom": |
| 160 | + raise RuntimeError("boom access should be skipped") |
| 161 | + return super().__getattribute__(name) |
| 162 | + |
| 163 | + self.assertIsInstance(Foo.boom, types.MemberDescriptorType) |
| 164 | + |
| 165 | + completer = rlcompleter.Completer(dict(f=Foo())) |
| 166 | + matches = completer.attr_matches('f.') |
| 167 | + self.assertIn('f.boom', matches) |
| 168 | + |
| 169 | + def test_raising_descriptor_completion_works(self): |
| 170 | + class ExplodingDescriptor: |
| 171 | + def __get__(self, obj, owner): |
| 172 | + if obj is None: |
| 173 | + return self |
| 174 | + raise RuntimeError("descriptor getter exploded") |
| 175 | + |
| 176 | + class Foo: |
| 177 | + boom = ExplodingDescriptor() |
| 178 | + |
| 179 | + completer = rlcompleter.Completer(dict(f=Foo())) |
| 180 | + matches = completer.attr_matches('f.') |
| 181 | + self.assertIn('f.boom', matches) |
138 | 182 |
|
139 | 183 | def test_uncreated_attr(self): |
140 | 184 | # Attributes like properties and slots should be completed even when |
|
0 commit comments