Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from

Conversation

Pranjal095
Copy link

@Pranjal095 Pranjal095 commented Mar 3, 2025

Merges PR #130427 implementing delattr suggestions by @sobolevn and PR #130455 adding tests for the feature by @Pranjal095

Note: This PR's sole purpose is to combine the feature implementation from PR #130427 with the test cases from PR #130455. All original commits have been preserved to retain proper authorship.

@picnixz picnixz changed the title Merge PR #130427 and PR #130455 implementing delattr suggestions gh-130425: Add "Did you mean [...]" suggestions for del obj.attr Mar 3, 2025
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

I also don't think that merging a fix with tests into one PR is a good idea. When we have a fix and new tests - we usually merge them as different PRs, that's the first time I see that we combine PRs :)

self.assertIn("'bluch'", self.get_suggestion(A(), '_luch'))
self.assertIn("'bluch'", self.get_suggestion(A(), '_bluch'))
obj = A()
if operation == "getattr":
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't quite like the current design :(
It would be even more complex, when we add setattr tests (btw, I think that they should also be added in this PR).

Can we instead create a base class out of existing testcase? And then create three subclasses which would look like so:

class GetattrSuggestionsTests(BaseSuggestionsTests, unittest.TestCase):
    def get_suggestion(self, obj, name):
        # get suggestions using `getattr`

class SetattrSuggestionsTests(BaseSuggestionsTests, unittest.TestCase):
    def get_suggestion(self, obj, name):
        # get suggestions using `setattr`

# the same for `delattr`

Copy link
Author

@Pranjal095 Pranjal095 Mar 4, 2025

Choose a reason for hiding this comment

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

I'll first refactor the tests as per your suggestion, and keep that as a separate commit.
I was unsure of adding setattr suggestion tests to this PR because:

  1. The concerning issue was raised for adding delattr suggestions alone.
  2. There are multiple ways to simulate an AttributeError for setattr (custom __slots__, @property etc.), and I felt it would be better to discuss the appropriate testing mechanism in a separate PR.

Copy link
Author

Choose a reason for hiding this comment

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

I have made the requested changes as per the refactor request. Kindly review the PR again.

Copy link
Author

Choose a reason for hiding this comment

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

Hello, just a gentle reminder to review the PR changes whenever convenient:) @sobolevn @picnixz

@bedevere-app
Copy link

bedevere-app bot commented Mar 4, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz
Copy link
Member

picnixz commented Mar 4, 2025

I also don't think that merging a fix with tests into one PR is a good idea

I would have actually expected that to be a feature and not a fix actually!

When we have a fix and new tests - we usually merge them as different PRs, that's the first time I see that we combine PRs

I actually always combined my fixes with my tests to check indeed that my fix is correct. Same for features.

@Pranjal095 Pranjal095 requested a review from sobolevn March 5, 2025 12:39
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 18, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@Pranjal095 Pranjal095 requested a review from methane April 18, 2025 10:20
@Pranjal095
Copy link
Author

Hi @sobolevn @picnixz, it has been a while since I addressed the feedback on this PR and noticed this is still open. Would you mind taking another look when you have a moment? Let me know if there's anything further I can do.

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

The interface is now a bit too nested. We have many nested classes and this is not the best I think. I suggest the following:

class AttributeSuggestions:
    def get_suggestion(...): ...

class GetattrSuggestions(AttributeSuggestions): ...
class DelattrSuggestions(AttributeSuggestions): ...
class SetattrSuggestions(AttributeSuggestions): ...

And then create the additional classes as you did that inherit from different mixins. But we don't need to touch SuggestionFormattingTestBase for delattr/getattr/hasattr etc. We can just make a separate class. If there is a common interface between SuggestionFormattingTestBase and those classes, make an even top class, say SuggestionFormattingTestBaseParent and SuggestionFormattingTestBase would inherit from it. That way you can share a common interface (I don't know if I'm clear enough).

@picnixz picnixz marked this pull request as draft July 12, 2025 15:06
@Pranjal095 Pranjal095 force-pushed the delattr-suggestions-combined branch from 0b58966 to 0ecb6d8 Compare July 12, 2025 15:06
@picnixz
Copy link
Member

picnixz commented Jul 12, 2025

Please avoid force-pushing. I'm going to close this one as many people were notified and suggeset you to create a fresh PR.

@AlexWaygood AlexWaygood removed their request for review July 12, 2025 15:07
@picnixz picnixz closed this Jul 12, 2025
@Pranjal095 Pranjal095 deleted the delattr-suggestions-combined branch July 12, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy