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 is allowed in methods of the descriptor protocol #742

Open
jonhnanthan opened this issue Jan 15, 2024 · 1 comment
Labels
bug Unexpected or incorrect user-visible behavior inline-refactor

Comments

@jonhnanthan
Copy link

Steps to reproduce the behavior:

  1. Code before refactoring:
class Descriptor:
    def __get__(self, instance, owner):
        return 40
  1. Apply the Inline Method refactoring to the method __get__.

  2. Expected code after refactoring: the same as the original. It would be nice if Rope could emit a warning that applying the refactoring to this type of class is not allowed.

  3. Rope produces the result below:

class Descriptor:
    pass
@jonhnanthan jonhnanthan added the bug Unexpected or incorrect user-visible behavior label Jan 15, 2024
@lieryan
Copy link
Member

lieryan commented Jan 29, 2024

Thanks for testing and describing these corner cases.

We may be able to create a new InlineDescriptor mechanism to implement something of this nature, but I don't know if this is something that can be done in a generic way given how flexible __get__ can get.

I don't think there's much we can really do here, other than, as you say, forbidding this refactoring, which should be pretty simple, we can just check that we don't allow inlining this dunder method.

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