summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKathryn Lingel <kathryn@lingel.net>2019-05-06 12:16:29 -0700
committerDamien George <damien@micropython.org>2021-05-02 23:11:03 +1000
commit1f1a54d0b1371efcfec6ca1b03d21b07a908c70d (patch)
tree9ffd727418a9934ae9aaa0e5f0b72fbce14f7f13
parentaa061ae391f2a8fbb16ace31ae0e4ae35b6ad5e9 (diff)
downloadmicropython-1f1a54d0b1371efcfec6ca1b03d21b07a908c70d.tar.gz
micropython-1f1a54d0b1371efcfec6ca1b03d21b07a908c70d.zip
py/repl: Filter private methods from tab completion.
Anything beginning with "_" will now only be tab-completed if there is already a partial match for such an entry. In other words, entering foo.<tab> will no longer complete/list anything beginning with "_". Originally at adafruit#1850 Signed-off-by: Kathryn Lingel <kathryn@lingel.net>
-rw-r--r--py/repl.c5
-rw-r--r--tests/unix/extra_coverage.py.exp10
2 files changed, 10 insertions, 5 deletions
diff --git a/py/repl.c b/py/repl.c
index c758fc067b..3b1837031b 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -197,6 +197,11 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print
for (qstr q = MP_QSTR_ + 1; q < nqstr; ++q) {
size_t d_len;
const char *d_str = (const char *)qstr_data(q, &d_len);
+ // special case; filter out words that begin with underscore
+ // unless there's already a partial match
+ if (s_len == 0 && d_str[0] == '_') {
+ continue;
+ }
if (s_len <= d_len && strncmp(s_start, d_str, s_len) == 0) {
mp_load_method_protected(obj, q, dest, true);
if (dest[0] != MP_OBJ_NULL) {
diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp
index d97de2c0ef..ab4d977741 100644
--- a/tests/unix/extra_coverage.py.exp
+++ b/tests/unix/extra_coverage.py.exp
@@ -28,11 +28,11 @@ RuntimeError:
# repl
ame__
-__class__ __name__ argv atexit
-byteorder exc_info exit getsizeof
-implementation maxsize modules path
-platform print_exception stderr
-stdin stdout version version_info
+argv atexit byteorder exc_info
+exit getsizeof implementation maxsize
+modules path platform print_exception
+stderr stdin stdout version
+version_info
ementation
# attrtuple
(start=1, stop=2, step=3)