Bug report
Bug description:
In BPO 44752 (#88915), it was reported that tab completions execute @property getters. This was fixed in two stages:
- bpo-44752: Make rlcompleter not call
@propertymethods #27401: no longer call property getters - bpo-44752: Make rlcompleter not call
@propertymethods #27401: No longer catch errors raised by a call to getattr.
It looks like when investigating/solving this issue, it was unconsidered that @property isn't the only case where calling an underlying method might be undesirable. For example, in the NVDA project, we have the following non-data descriptor (simplified for clarity):
class Getter: def __init__(self, fget): self.fget = fget def __get__(self, instance, owner): if isinstance(self.fget, classmethod): return self.fget.__get__(instance, owner)() elif instance is None: return self return self.fget(instance) class SomeClass: @Getter def some_prop(self): raise NotImplementedError
If we'd create an instance of SomeClass and try to autocomplete, rlcompleter.Completer.attr_matches would fail with the NotImplementedError raised by some_prop
I'd propose one of the following:
- Restore the try/except removed in bpo-44752: Make rlcompleter not call
@propertymethods #27401 - Create abstract classes for descriptors in _collections_abc (e.g. ImplementsGet, ImplementsSet, ImplementsDelete) and in rlcompleter, rather than checking for
isinstance(obj, property), useisinstance(obj, ImplementsGet). This might cause false positives for method descriptors though.
CPython versions tested on:
3.11
Operating systems tested on:
Windows
Linked PRs
- gh-112821: Fix rlcompleter failures on objects with descriptors #149577
- [3.15] gh-112821: Fix rlcompleter failures on objects with descriptors (GH-149577) #149656
- [3.14] gh-112821: Fix rlcompleter failures on objects with descriptors (GH-149577) #149657
- [3.13] gh-112821: Fix rlcompleter failures on objects with descriptors (GH-149577) #149658