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

Iterator / context manager extraction #95

Open
talwrii opened this issue Oct 30, 2017 · 1 comment
Open

Iterator / context manager extraction #95

talwrii opened this issue Oct 30, 2017 · 1 comment

Comments

@talwrii
Copy link
Contributor

talwrii commented Oct 30, 2017

So yeah, I don't seem to be a good beta tester: you might not want to immediately implement this. But this struck me as an interesting idea and this project feels like the correct community for useable python refactoring tools, so I thought I'd throw this idea up here.

Sometimes I don't want to extract a region... so much as everything apart from a region.

An example:

def f():
    for x in blah():
        if filter(x):
           continue
        do_stuff(x)

# should become

def iterate_x():
     for x in blah:
         if filter(x):
             continue
         else:
               yield x

def f():
     for x in iterate_x():
          do_stuff(x)

The same idea applies to context managers.

@abingham
Copy link
Owner

It's an interesting idea. I definitely see the value of the specific refactoring you made above, separating the sequence generation from the element handling. If that could be defined in terms of existing rope refactorings then I'd be happy to include it in traad.

If if turns out that this would require a new form of refactoring, though, you probably need to talk with the rope project.

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

No branches or pull requests

2 participants