-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/repl: Skip private variables when printing tab completion options. #17108
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?
Conversation
05a5c7a
to
8c01246
Compare
Code size report:
|
py/repl.c
Outdated
@@ -218,7 +218,8 @@ 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) { | |||
// check if item matches prefix and it's not a hidden attribute (starting with single underscore) | |||
if (s_len <= d_len && strncmp(s_start, d_str, s_len) == 0 && (d_str[0] != '_' || (d_len > 1 && d_str[1] == '_'))) { |
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.
Wouldn't it be simpler and maybe smaller code to follow the pattern of find_completions()
like this:
if (s_len == 0 && d_str[0] == '_') {
continue;
}
if (s_len <= d_len && strncmp(...) == 0) {
?
It's actually not easy to make a test for this that is robust because the bug relies on a certain ordering of qstrs in the frozen set of qstrs (it needs qstrs beginning with underscore to appear between the first and last items that match the tab completion). So maybe it's not worth adding a test for? Does the test you added fail prior to the fix in this PR? |
I'll test without the fix again; asyncio did include an This test also highlighted an issue in the original version of this commit in that it was also hiding |
8c01246
to
9dceed4
Compare
Any '_' variables/functions in frozen modules are currently printed. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
9dceed4
to
ee5694f
Compare
Summary
The tab completion on repl is intended to not show any attributes starting with a single
_
character, however variables/functions in frozen modules are are currently shown.This PR introduces a change to py/repl to skip private variables when printing tab completion options.
Originally included in #17011
Testing
A unit test has added which covers this, currently based on the asyncio module which is generally frozen in.
However looking again now maybe it would be better to add a suitable function / attribute to
./tests/frozen/frozentest.py
and test against that, assuming it should have the same behavior?