Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

a python refactoring library...

Project description


Rope is a python refactoring library.

New Features

  • added “use function” refactoring
  • completing names after from-imports
  • adding resources parameter to some refactorings
  • added rope.contrib.autoimport module
  • handling unsure matches in restructurings
  • deprecated in_file argument of Rename.get_changes()

Use Function Refactoring

It tries to find the places in which a function can be used and changes the code to call it instead. For instance if mod1 is:

def square(p):
    return p ** 2

my_var = 3 ** 2

and mod2 is:

another_var = 4 ** 2

if we perform “use function” on square function, mod1 will be:

def square(p):
    return p ** 2

my_var = square(3)

and mod2 will be:

import mod1
another_var = mod1.square(4)

(Example from the mailing list)

Completing Names After From Imports

rope.base.codeassist.code_assist now completes the names after from-imports, too. For instance completing:

from shutil import rm

will propose rmtree.

Refactoring Resources Parameter

I’ve added a new parameter to some refactorings, restructure and find occurrences called resources. If it is a list of Files, all other resources in the project are ignored and the refactoring only analyzes them; if it is None all python module in the project will be analyzed. Using this parameter, IDEs can let the user limit the files on which a refactoring should be applied.

I’ve also deprecated the “in_file” parameter of rename refactoring; resources can be used instead.


rope.contrib.autoimport module has been added. This module can be used to find the modules that provide a name. IDEs can use this module to auto-import names. AutoImport.get_modules() returns the list of modules with the given global name. AutoImport.import_assist() tries to find the modules that have a global name that starts with the given prefix.

Project details

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page