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

  • inline variable can now inline variable in other modules
  • handling only_current option for inline in other modules
  • better extension module handling
  • added rope.contrib.findit.find_definition()
  • added rope.contrib.changestack module to perform many refactorings as a single command
  • added rope.contrib.fixmodnames for fixing module and package names
  • added rope.contrib.finderrors module for finding bad name and attribute accesses
  • added region field to rope.contrib.findit.Location
  • added remove_self argument to codeassist.get_calltip()

Inline Refactoring Enhancements

Inline variable can now inline variables in other (the ones not containing the definition) modules. It adds import to changed modules when needed.

One problem for inline refactoring is from-imports. If a name is imported as from mod import f then after removing the definition of f, these imports should be removed; rope does this now.

Also only_current option of inline didn’t work in other modules; it was fixed.


changestack module can be used to perform many refactorings on top of each other as one bigger command. It can be used like:

stack = ChangeStack(project, 'my big command')


changes = stack.merged()

Now changes can be previewed or performed as before.


This module is useful when you want to rename many of the modules in your project. That can happen specially when you want to change their naming style.

For instance:

fixmods = FixModuleNames(project)
changes = fixmods.get_changes(fixer=str.lower)

renames all modules and packages to use lower-cased chars. You can tell it to use any other style by using the fixer argument.


find_errors function can be used to find possible bad name and attribute accesses. As an example:

errors = find_errors(project, project.get_resource(''))
for error in errors:
    print '%s: %s' % (error.lineno, error.error)

prints possible errors for file.

Currently this module is experimental and reports many false-positives. Contributions are welcome.


This function finds the definition of a name, just like the older rope.contrib.codeassist.get_definition_location function. The difference is it returns a findit.Location object like other functions is findit module.

Also rope.contrib.findit.Location has a new field called region it is a tuple that holds the start and end offset of the occurrence; this can probably be used in IDE’s that highlight locations.

Better Extension Module Handling

extension_modules project config tells rope to import these modules if their source code cannot be found. Rope can now handle nested extension modules in normal packages.

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