Skip to content

gh-153506: Fix IDLE crash on non-iterable __all__#153527

Closed
muhamedfazalps wants to merge 5 commits into
python:mainfrom
muhamedfazalps:fix/idle-all-crash
Closed

gh-153506: Fix IDLE crash on non-iterable __all__#153527
muhamedfazalps wants to merge 5 commits into
python:mainfrom
muhamedfazalps:fix/idle-all-crash

Conversation

@muhamedfazalps

Copy link
Copy Markdown

Problem

Fixes gh-153506

When a module has __all__ set to a non-iterable value (like None or an integer), pressing Tab for module-name completion in IDLE's shell raises an uncaught TypeError.

Root Cause

autocomplete.py calls sorted(eval("__all__", namespace)) without checking if the value is iterable. If __all__ = None (an easy typo), sorted() raises TypeError.

Solution

Add a hasattr(__all__, '__iter__') check before calling sorted(). If __all__ is not iterable, fall back to the standard private-name filtering ([s for s in bigl if s[:1] != '_']).

This is consistent with how Python's import system handles non-iterable __all__ — it raises an error, but IDLE should be resilient and fall back gracefully.

Testing

Verified that:

  1. __all__ = None no longer crashes — falls back to standard completion
  2. __all__ = ['valid', 'names'] still works correctly
  3. Normal completion without __all__ still works

When a module has __all__ set to a non-iterable value (like None),
pressing Tab for module-name completion raised an uncaught TypeError.

Now checks hasattr(__all__, '__iter__') before calling sorted(),
falling back to the standard private-name filtering.
@bedevere-app

bedevere-app Bot commented Jul 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented Jul 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented Jul 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented Jul 11, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland

Copy link
Copy Markdown
Member

Closing in favour of existing PR: #153507

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.

IDLE module-name completion crashes on a non-iterable __all__

2 participants