Title: rlcompleter suggests attributes not accessible on instances (e.g., Enum member __name__) · Issue #139819 · python/cpython · GitHub
Open Graph Title: rlcompleter suggests attributes not accessible on instances (e.g., Enum member __name__) · Issue #139819 · python/cpython
X Title: rlcompleter suggests attributes not accessible on instances (e.g., Enum member __name__) · Issue #139819 · python/cpython
Description: Bug report Bug description: While looking into gh-139398, I noticed a separate issue: some tab-completion suggestions are offered even though they do not actually exist / are not accessible. For example, on an Enum member, __name__ is su...
Open Graph Description: Bug report Bug description: While looking into gh-139398, I noticed a separate issue: some tab-completion suggestions are offered even though they do not actually exist / are not accessible. For ex...
X Description: Bug report Bug description: While looking into gh-139398, I noticed a separate issue: some tab-completion suggestions are offered even though they do not actually exist / are not accessible. For ex...
Opengraph URL: https://github.com/python/cpython/issues/139819
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"rlcompleter suggests attributes not accessible on instances (e.g., Enum member __name__)","articleBody":"# Bug report\n\n### Bug description:\n\nWhile looking into gh-139398, I noticed a separate issue: some tab-completion suggestions are offered even though they do not actually exist / are not accessible.\n\nFor example, on an Enum member, `__name__` is suggested but accessing it raises AttributeError. Tracing the behavior shows rlcompleter includes class-level names even when they aren’t accessible from the instance; adding a guard in rlcompleter fixes it (PR incoming).\n\n#### Reproduce\n\n```python\nfrom enum import Enum\nclass Color(Enum):\n BLUE = 1\n\n# In the REPL, press \u003cTAB\u003e after typing:\nColor.BLUE.__\n# '__name__' appears in the suggestions.\n\nColor.BLUE.__name__ # AttributeError: 'Color' object has no attribute '__name__'\n```\n\n#### Expected\nOnly attributes actually accessible on the instance should be suggested.\n\n#### Actual\nClass-level names show up for instances (e.g., Enum members), leading to AttributeError when accessed.\n\n#### Fix\n\n```diff\ndiff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py\nindex 23eb0020f42..521f41a869d 100644\n--- a/Lib/rlcompleter.py\n+++ b/Lib/rlcompleter.py\n@@ -39,6 +39,9 @@\n\n __all__ = [\"Completer\"]\n\n+# Sentinel object to distinguish \"missing\" from \"present but None\"\n+_SENTINEL = object()\n+\n class Completer:\n def __init__(self, namespace = None):\n \"\"\"Create a new completer for the command line.\n@@ -188,9 +191,9 @@ def attr_matches(self, text):\n # property method, which is not desirable.\n matches.append(match)\n continue\n- if (value := getattr(thisobject, word, None)) is not None:\n+ if (value := getattr(thisobject, word, _SENTINEL)) is not _SENTINEL:\n matches.append(self._callable_postfix(value, match))\n- else:\n+ elif word in getattr(type(thisobject), '__slots__', ()):\n matches.append(match)\n if matches or not noprefix:\n break\n```\n\n#### Also observed (bogus suggestions)\n```\n['Color.BLUE.__iter__',\n 'Color.BLUE.__getitem__',\n 'Color.BLUE.__members__',\n 'Color.BLUE.__contains__',\n 'Color.BLUE.__qualname__',\n 'Color.BLUE.__len__',\n 'Color.BLUE.__name__']\n# Additionally seen among bogus suggestions:\n'Enum.__abstractmethods__'\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-139820\n* gh-151222\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ttw225","@type":"Person","name":"ttw225"},"datePublished":"2025-10-09T03:53:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/139819/cpython/issues/139819"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ef21afcd-1a46-74fe-d5fe-70f9a7171bdc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8142:229C6A:7C166D:A5C998:6A530DB6 |
| html-safe-nonce | 4f967cc91b85c3b0065d9e3e66b085e9b7bff12bb16e8afed381b7ccb1220532 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTQyOjIyOUM2QTo3QzE2NkQ6QTVDOTk4OjZBNTMwREI2IiwidmlzaXRvcl9pZCI6IjE1MDkwNDAzOTQ3NzU3NjAzMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1550bfdb90d8c5a45250b734ccdc1b2c8b3dff73ca55f8f3abb444fdf03465ce |
| hovercard-subject-tag | issue:3497545867 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139819/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8552b7ac9031d45a3ad9aed0f7f3baa2a3b2c2981c77ea6200b929c5cd098792/python/cpython/issues/139819 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8552b7ac9031d45a3ad9aed0f7f3baa2a3b2c2981c77ea6200b929c5cd098792/python/cpython/issues/139819 |
| og:image:alt | Bug report Bug description: While looking into gh-139398, I noticed a separate issue: some tab-completion suggestions are offered even though they do not actually exist / are not accessible. For ex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ttw225 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width