Skip to main content

a python refactoring library...

Project description

Overview

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.

rope.contrib.changestack

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')

#..
stack.push(refactoring1.get_changes())
#..
stack.push(refactoring2.get_changes())
#..
stack.push(refactoringX.get_changes())

stack.pop_all()
changes = stack.merged()

Now changes can be previewed or performed as before.

rope.contrib.fixmodnames

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)
project.do(changes)

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

rope.contrib.finderrors

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

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

prints possible errors for mod.py file.

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

rope.contrib.findit.find_definition

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


Release history Release notifications | RSS feed

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page