GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Provide name suggestions for failed attribute deletions · Issue #130425 · python/cpython

Provide name suggestions for failed attribute deletions #130425

New issue
Copy link
New issue
Copy link
Closed
Closed
Provide name suggestions for failed attribute deletions#130425
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@Pranjal095
Pranjal095
opened on Feb 21, 2025
Issue body actions

Feature or enhancement

Proposal:

This was initially mentioned as a comment in issue #130399.

class A:
    pass

a = A()
a.abcde = 1
del a.abcdf # typo

Current Output

Traceback (most recent call last):
  File "<python-input-0>", line 6, in <module>
    del a.abcdf # typo
        ^^^^^^^
AttributeError: 'A' object has no attribute 'abcdf'

CPython provides name suggestions when an attribute lookup (obj.attr) fails, but it does not provide similar suggestions when an attribute deletion (del obj.attr) fails. This brings about an inconsistency with regards to the developer experience offered by the language.

Expected Output

Traceback (most recent call last):
  File "<python-input-0>", line 6, in <module>
    del a.abcdf # typo
        ^^^^^^^
AttributeError: 'A' object has no attribute 'abcdf'. Did you mean: 'abcde'?

Advantages

  • Helps users quickly identify typos in attribute deletions.
  • CPython already provides name suggestions for failed attribute lookups (obj.attr), so deletions (del obj.attr) should behave similarly.
  • Suggestions are only generated when an attribute deletion fails, and hence has a minimal performance impact.

Note
CPython version - CPython main branch
Operating system - Ubuntu 22.04

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-130425: Add "Did you mean" suggestion for del obj.attr #130427
  • gh-130425: Add "Did you mean [...]" suggestions for del obj.attr #130799
  • gh-130425: Add "Did you mean [...]" suggestions for del obj.attr #136588

Activity

  1. Pranjal095
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Feb 21, 2025
  2. StanFromIreland commented on Feb 21, 2025

    @StanFromIreland
    StanFromIreland
    on Feb 21, 2025
    Member
    More actions

    Possibly a bug?

  3. Pranjal095 commented on Feb 21, 2025

    @Pranjal095
    Pranjal095
    on Feb 21, 2025
    ContributorAuthor
    More actions

    It does seem like something obvious that's missing, but I wasn't 100% sure. Anyway, I was able to implement this by checking for deletion errors in PyObject_SetAttr function (Objects/object.c) and accordingly applying _PyObject_SetAttributeErrorContext.
    Should I raise the PR?

  4. sobolevn
    added a commit that references this issue on Feb 21, 2025

    pythongh-130425: Add "Did you mean" suggestion for `del obj.attr`

    1177f20
  5. sobolevn commented on Feb 21, 2025

    @sobolevn
    sobolevn
    on Feb 21, 2025
    Member
    More actions

    @Pranjal095 thanks for raising this! I suspect that the problem is in a bit different place. I proposed my solution. But, looks like we don't have enough tests for this feature.

    Do you want to contribute? :)

  6. Pranjal095 commented on Feb 21, 2025

    @Pranjal095
    Pranjal095
    on Feb 21, 2025
    ContributorAuthor
    More actions

    I checked out your solution, and yes, it is much more suitable than my proposed change. Glad I could help.
    Also, I would love to contribute to the tests for this feature with your guidance!

  7. StanFromIreland commented on Feb 21, 2025

    @StanFromIreland
    StanFromIreland
    on Feb 21, 2025
    Member
    More actions

    Created #130428 for coordination:-)

  8. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Feb 22, 2025
  9. Pranjal095
    changed the title [-]Provide Name Suggestions for Failed Attribute Deletions[/-] [+]Provide name suggestions for Failed Attribute Deletions[/+] on Feb 24, 2025
  10. Pranjal095
    changed the title [-]Provide name suggestions for Failed Attribute Deletions[/-] [+]Provide name suggestions for failed attribute deletions[/+] on Feb 24, 2025
  11. Pranjal095
    added a commit that references this issue on Jul 12, 2025

    pythongh-130425: Add "Did you mean" suggestion for `del obj.attr`

    ee4081f
  12. Pranjal095 commented on Aug 9, 2025

    @Pranjal095
    Pranjal095
    on Aug 9, 2025
    ContributorAuthor
    More actions

    @sobolevn I’ve really enjoyed working on this issue and am excited to see it come to life! Just dropping a friendly reminder to review the PR whenever you get a chance.

  13. encukou
    added a commit that references this issue on Aug 22, 2025

    gh-130425: Add "Did you mean [...]" suggestions for `del obj.attr` (G…

    f27af8b
  14. encukou commented on Aug 22, 2025

    @encukou
    encukou
    on Aug 22, 2025
    Member
    More actions

    Thank you for the feature!

    There's one more possible follow-up: cases where a class raises its own AttributeError from __delattr__. The test_suggestions_no_args and test_suggestions_invalid_args tests are currently getattr-only.

    Reacted by Pranjal Prajapati
  15. Pranjal095 commented on Aug 22, 2025

    @Pranjal095
    Pranjal095
    on Aug 22, 2025
    ContributorAuthor
    More actions

    Thanks for the follow-up suggestion! I'm currently seeing several possible places in the C code where this could be implemented, and I’m a bit unsure where I should focus my attention first. Could you clarify which area would be the right starting point?

  16. hugovk commented on Oct 23, 2026

    @hugovk
    hugovk
    on Oct 23, 2026
    Member
    More actions

    Closing, #130428 tracks the test suggestions.

  17. hugovk
    closed this as completedon Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.