Skip to content

gh-153506: Guard IDLE completions against a non-iterable __all__#153507

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:idlelib-autocomplete-all-guard
Open

gh-153506: Guard IDLE completions against a non-iterable __all__#153507
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:idlelib-autocomplete-all-guard

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

autocomplete.AutoComplete.fetch_completions evaluated __main__.__all__ in the ATTRS empty-prefix branch with sorted(eval("__all__", namespace)) and no guard, while the sibling non-empty-prefix branch already wrapped the equivalent sorted(entity.__all__) in try/except and returned empty lists on failure. A non-iterable __all__ in the interactive namespace (for example __all__ = None) therefore raised TypeError on Tab at an empty prefix instead of showing completions.

This guards the empty-prefix branch the same way, returning empty completion lists when __all__ cannot be evaluated or sorted, and leaves the sibling branch untouched. A regression test drives fetch_completions with a patched __main__.__all__ and asserts empty lists, and that a valid namespace still yields completions.

The ATTRS empty-prefix branch of autocomplete.fetch_completions() evaluated __main__.__all__ without a guard, while the non-empty sibling branch already caught failures, so a non-iterable __all__ in the interactive namespace raised TypeError on Tab. Catch the failure and return empty completion lists instead, leaving the sibling branch untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant