-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/modmicropython: Expose repl_autocomplete as python function. #17011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
py/modmicropython: Expose repl_autocomplete as python function. #17011
Conversation
Code size report:
|
e1aa321
to
5dd9831
Compare
Adding autocomplete for aiorepl is very desirable, and this is looking promising! Here are some of the tests I ran: >>>import micropython
>>>micropython.repl_autocomplete("impo") # Should complete 'import'
'rt '
>>> class Foo:
... def _bar():
... pass
... def alpha():
... pass
>>> micropython.repl_autocomplete("f = Fo") # Should complete Foo
'o'
>>>f = Foo()
>>> micropython.repl_autocomplete("f.") # Should complete alpha (ignoring _bar)
'alpha' Note that this is correct and consistent with MicroPython's built-in tab completion - but differs in some cases to CPython, at least at v3.12. CPython will also supply parentheses, ie it would return I also tested a module with private members and they were also correctly filtered out. Looks good! |
Perhaps that should just be documented as such. I'd be fine with consistent behavior with the MicroPython repl. |
py/repl.c
Outdated
@@ -218,7 +218,7 @@ static void print_completions(const mp_print_t *print, | |||
for (qstr q = q_first; q <= q_last; ++q) { | |||
size_t d_len; | |||
const char *d_str = (const char *)qstr_data(q, &d_len); | |||
if (s_len <= d_len && strncmp(s_start, d_str, s_len) == 0) { | |||
if (s_len <= d_len && strncmp(s_start, d_str, s_len) == 0 && d_str[0] != '_') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please break this out into a separate PR. It'll need changes to the tests as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split out to #17108 with a unit test (which might need some more updating to ensure the test is consistent / works across ports etc?)
5dd9831
to
59eccf8
Compare
59eccf8
to
bdb98b0
Compare
Ok I'm really not sure why the unit tests are still failing on some builds; unix standard in particular. The test passes for me locally with the same build. |
Used to add tab completion to aiorepl. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
bdb98b0
to
6709f5e
Compare
Summary
The
mp_repl_autocomplete()
function inpy/repl.c
provides the tab complete functionality for the standard repl.It would be highly beneficial to also add tab completion to aiorepl which requires exposing this function to python.
This PR also includes a minor change to py/repl: Skip private variables when printing tab completion options.
Any '_' variables/functions in frozen modules are currently printed which is fixed by this.
Testing
While the aiorepl integration hasn't been written yet, this PR is only exposing existing functionality and includes basic unit tests.