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

The Inline Method is allowed for constructor methods #750

Open
jonhnanthan opened this issue Jan 19, 2024 · 1 comment
Open

The Inline Method is allowed for constructor methods #750

jonhnanthan opened this issue Jan 19, 2024 · 1 comment

Comments

@jonhnanthan
Copy link

Python’s instantiation process starts with a call to the class constructor, which triggers the instance creator, __new__(), to create a new empty object.
The process continues with the instance initializer, __init__(), which takes the constructor’s arguments to initialize the newly created object.
Rope allows applying the Inline Method refactoring to the __new__() method.

Steps to reproduce the behavior:

  1. Code before refactoring:
unicode = str


class MyClass(unicode):
    def __new__(cls, string):
        return super(MyClass, cls).__new__(cls, string)

    def __init__(self, string):
        self.value = string
  1. Apply the Inline Method refactoring to MyClass.__new__
@jonhnanthan jonhnanthan added the bug Unexpected or incorrect user-visible behavior label Jan 19, 2024
@lieryan
Copy link
Member

lieryan commented Feb 5, 2024

I'm removing the bug label, this isn't a bug, inlining __new__ currently isn't supported so it's a new feature.

It should be possible to implement, inlining classmethods already mostly works and inlining __new__ is similar to inlining code that looks like so:

unicode = str


class MyClass(unicode):
    def __new__(cls, string):
        return super(MyClass, cls).__new__(cls, string)

    def __init__(self, string):
        self.value = string

instance = MyClass.__new__(...)

There are some tweaking needing to fix the super() call, but currently inlining classmethod don't fix that either, so that can be done together with that.

@lieryan lieryan added enhancement and removed bug Unexpected or incorrect user-visible behavior labels Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants