abingham / traad

An JSON+HTTP server for the rope Python refactoring library
MIT License
107 stars 20 forks source link

Support for inlining of variables #90

Closed talwrii closed 7 years ago

talwrii commented 7 years ago

This comes up more than one imagines. I have hit this as part of refactoring.

Example:

for x in xs:
    a = f(x)
    yield g(a)

I want to extract f and g, so I manually change this code to

for x in xs:
    a = f(x)
    result = g(a)
    yield result

And then use extract out lines 2 and 3 to get

for x in xs:
    result = new_method(x)
    yield result

I then need to incline result in both new_method and here.

Variable inlining is supported in rope. So I imagine it mightn't be too much work to implement.

talwrii commented 7 years ago

This also comes up in order to make the arguments that a function take more specific.

c = f(a.b)
d = g(c)

I want to turn this into a function that takes a.b as an argument (rather than a).

To cause this to happen I convert the code to the following

input = a.b
c = f(input)
d = g(c)

And then extract lines 2, and 3

 input = a.b
 d = new_method(input)

At this point I want / need to inline input again.

abingham commented 7 years ago

This would certainly be nice have. Hopefully I'll get some time soon to work it.

abingham commented 7 years ago

I've added support for rope's inline refactoring in the added-inline branch. Give it a try and let me know what you think.

If you're using traad via the emacs extension, there's an associated branch in emacs-traad.

This has only been lightly tested; I wrote it in some free time at an airport, so it was a bit of a rush job.

talwrii commented 7 years ago

That was quick, and is quite exciting. Trying this out now.

abingham commented 7 years ago

Let me know if it works for you. If so, I'll merge it into main.

abingham commented 7 years ago

@talwrii Did this work for you?

abingham commented 7 years ago

@talwrii I'm going to assume that this works and merge it in.