Skip to content
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

Inline method refactoring applied to rich comparison methods #758

Open
researcher175 opened this issue Feb 26, 2024 · 0 comments
Open

Inline method refactoring applied to rich comparison methods #758

researcher175 opened this issue Feb 26, 2024 · 0 comments
Labels
bug Unexpected or incorrect user-visible behavior inline-refactor

Comments

@researcher175
Copy link

researcher175 commented Feb 26, 2024

Inline method refactoring allows for rich comparison methods.
It would be nice if Rope sent an alert to the user to avoid applying the transformation to rich comparison methods.

Steps to reproduce the behavior:

  1. Code before refactoring:
class GFG:
    def __init__(self, Marks):
        self.Marks = Marks

    def _cmpkey(self):
        return self.Marks

    def _compare(self, other, method):
        try:
            return method(self._cmpkey(), other._cmpkey())
        except (AttributeError, TypeError):
            return NotImplemented

    def __lt__(self, other):
        return self._compare(other, lambda s, o: s < o)

student1_marks = GFG(90)
student2_marks = GFG(88)

print(student1_marks < student2_marks)
print(student2_marks < student1_marks)
  1. Apply the Inline Method refactoring to 'GFG.__lt__'
@researcher175 researcher175 added the bug Unexpected or incorrect user-visible behavior label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect user-visible behavior inline-refactor
Projects
None yet
Development

No branches or pull requests

2 participants