LeonarddeR · GitHub

Bug report

Bug description:

In BPO 44752 (#88915), it was reported that tab completions execute @property getters. This was fixed in two stages:

  1. bpo-44752: Make rlcompleter not call @property methods #27401: no longer call property getters
  2. bpo-44752: Make rlcompleter not call @property methods #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:

  1. Restore the try/except removed in bpo-44752: Make rlcompleter not call @property methods #27401
  2. Create abstract classes for descriptors in _collections_abc (e.g. ImplementsGet, ImplementsSet, ImplementsDelete) and in rlcompleter, rather than checking for isinstance(obj, property), use isinstance(obj, ImplementsGet). This might cause false positives for method descriptors though.

CPython versions tested on:

3.11

Operating systems tested on:

Windows

Linked PRs

Read the original on github.com ↗