Jack DeVries <jdevries3...@gmail.com> added the comment:

> Now that I see hasattr() uses getattr(), it looks like the tab completion 
> issue might not stem from line 155, but from line 180 
> (https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/rlcompleter.py#L180)
>  where it calls getattr().

That is correct! I was able to fix the undesirable behavior by adding an early 
exit condition if we appear to have a property object. I checked for the 
existence of a property object like this:

    class Foo:

        @property
        def bar(self):
            return 'baz'

    def is_property(object, attr):
        return isinstance(getattr(type(object), attr, None), property)

    assert is_property(Foo(), 'bar')

The code that follows line 180 in the loop just checks if ``object.attribute`` 
is callable, and whether the callable takes arguments in order to determine 
whether to add parenthesis to the completion. In my opinion, we never really 
want to add parenthesis when providing completion for a property attribute 
anyway, so there's no reason to go through that code block if we are dealing 
with a property.

I opened a GitHub PR. Let me know what you think!

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44752>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to