X Tutup
Skip to content

Commit 6fe3926

Browse files
committed
Issue #25590: Complete attribute names even if they are not yet created
1 parent f4ad5f5 commit 6fe3926

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Doc/whatsnew/3.6.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ Private and special attribute names now are omitted unless the prefix starts
120120
with underscores. A space or a colon can be added after completed keyword.
121121
(Contributed by Serhiy Storchaka in :issue:`25011` and :issue:`25209`.)
122122

123+
Names of most attributes listed by :func:`dir` are now completed.
124+
Previously, names of properties and slots which were not yet created on
125+
an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.)
126+
123127

124128
urllib.robotparser
125129
------------------

Lib/rlcompleter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ def attr_matches(self, text):
160160
for word in words:
161161
if (word[:n] == attr and
162162
not (noprefix and word[:n+1] == noprefix)):
163+
match = "%s.%s" % (expr, word)
163164
try:
164165
val = getattr(thisobject, word)
165166
except Exception:
166-
continue # Exclude properties that are not set
167-
word = self._callable_postfix(val, "%s.%s" % (expr, word))
168-
matches.append(word)
167+
pass # Include even if attribute not set
168+
else:
169+
match = self._callable_postfix(val, match)
170+
matches.append(match)
169171
if matches or not noprefix:
170172
break
171173
if noprefix == '_':

Lib/test/test_rlcompleter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def bar(self):
9292
self.assertEqual(completer.complete('f.b', 0), 'f.bar')
9393
self.assertEqual(f.calls, 1)
9494

95+
def test_uncreated_attr(self):
96+
# Attributes like properties and slots should be completed even when
97+
# they haven't been created on an instance
98+
class Foo:
99+
__slots__ = ("bar",)
100+
completer = rlcompleter.Completer(dict(f=Foo()))
101+
self.assertEqual(completer.complete('f.', 0), 'f.bar')
102+
95103
def test_complete(self):
96104
completer = rlcompleter.Completer()
97105
self.assertEqual(completer.complete('', 0), '\t')

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ Core and Builtins
8585
Library
8686
-------
8787

88+
- Issue #25590: In the Readline completer, only call getattr() once per
89+
attribute. Also complete names of attributes such as properties and slots
90+
which are listed by dir() but not yet created on an instance.
91+
8892
- Issue #25498: Fix a crash when garbage-collecting ctypes objects created
8993
by wrapping a memoryview. This was a regression made in 3.5a1. Based
9094
on patch by Eryksun.

0 commit comments

Comments
 (0)
X Tutup