Skip to content

gh-139819: rlcompleter – avoid suggesting attributes not accessible on instances#139820

Merged
ethanfurman merged 9 commits into
python:mainfrom
ttw225:fix/rlcompleter
Jun 9, 2026
Merged

gh-139819: rlcompleter – avoid suggesting attributes not accessible on instances#139820
ethanfurman merged 9 commits into
python:mainfrom
ttw225:fix/rlcompleter

Conversation

@ttw225

@ttw225 ttw225 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Fix tab-completion suggesting names that are not accessible on instances
(e.g., Enum members showing __name__).

Change

In rlcompleter.attr_matches(), when getattr(thisobject, word, None)
is None, only add the candidate if hasattr(thisobject, word) is true.

Effect

Removes bogus suggestions without affecting valid completions.

Bogus suggestions

['Color.BLUE.__iter__',
 'Color.BLUE.__getitem__',
 'Color.BLUE.__members__',
 'Color.BLUE.__contains__',
 'Color.BLUE.__qualname__',
 'Color.BLUE.__len__',
 'Color.BLUE.__name__']
# Additionally seen among bogus suggestions:
'Enum.__abstractmethods__'

@ttw225

ttw225 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Noted the CI Test failure. I’m working on a fix and will push soon.

@ttw225

ttw225 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Tests have passed. Thanks for reviewing!

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 30, 2026
@ethanfurman ethanfurman merged commit 81c1cdc into python:main Jun 9, 2026
52 checks passed
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Jun 9, 2026
…ible on instances (pythonGH-139820)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Comment thread Lib/rlcompleter.py
__all__ = ["Completer"]

# Sentinel object to distinguish "missing" from "present but None"
_SENTINEL = object()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the new sentinel builtin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants