# eric7.Plugins.CheckerPlugins.CodeStyleChecker.CodeStyleFixer

Module implementing a class to fix certain code style issues.

### Global Attributes

FixableCodeStyleIssues

### Classes

CodeStyleFixer | Class implementing a fixer for certain code style issues.
IndentationWrapper | Class used by fixers dealing with indentation.
LineShortener | Class used to shorten lines to a given maximum of characters.
Reindenter | Class to reindent badly-indented code to uniformly use four-space indentation.

### Functions

None

## CodeStyleFixer

Class implementing a fixer for certain code style issues.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

CodeStyleFixer | Constructor
__codeMatch | Private method to check, if the code should be fixed.
__findLogical | Private method to extract the index of all the starts and ends of lines.
__fixBlankLinesBefore | Private method to fix the need for blank lines before class, function and method definitions.
__fixD111 | Private method to fix docstring enclosed in wrong quotes.
__fixD112 | Private method to fix docstring 'r' in leading quotes.
__fixD121 | Private method to fix a single line docstring on multiple lines.
__fixD131 | Private method to fix a docstring summary not ending with a period.
__fixD141 | Private method to fix a function/method docstring preceded by a blank line.
__fixD142 | Private method to fix a class docstring not preceded by a blank line.
__fixD143 | Private method to fix a class docstring not followed by a blank line.
__fixD144 | Private method to fix a docstring summary not followed by a blank line.
__fixD145 | Private method to fix the last paragraph of a multi-line docstring not followed by a blank line.
__fixD221 | Private method to fix leading and trailing quotes of docstring not on separate lines.
__fixD242 | Private method to fix a class or function/method docstring preceded by a blank line.
__fixD243 | Private method to fix a class or function/method docstring followed by a blank line.
__fixD247 | Private method to fix a last paragraph of a docstring followed by a blank line.
__fixE101 | Private method to fix obsolete tab usage and indentation errors.
__fixE121 | Private method to fix the indentation of continuation lines and closing brackets.
__fixE122 | Private method to fix a missing indentation of continuation lines.
__fixE123 | Private method to fix the indentation of a closing bracket lines.
__fixE125 | Private method to fix the indentation of continuation lines not distinguishable from next logical line.
__fixE126 | Private method to fix over-indented/under-indented hanging indentation.
__fixE127 | Private method to fix over/under indented lines.
__fixE201 | Private method to fix extraneous whitespace.
__fixE221 | Private method to fix extraneous whitespace around operator or keyword.
__fixE225 | Private method to fix extraneous whitespaces around operator.
__fixE231 | Private method to fix missing whitespace after ',;:'.
__fixE251 | Private method to fix extraneous whitespace around keyword and default parameter equals.
__fixE261 | Private method to fix whitespace before or after inline comment.
__fixE304 | Private method to fix superfluous blank lines after a function decorator.
__fixE401 | Private method to fix multiple imports on one line.
__fixE501 | Private method to fix the long lines by breaking them.
__fixE502 | Private method to fix redundant backslash within brackets.
__fixE701 | Private method to fix colon-separated compound statements.
__fixE702 | Private method to fix semicolon-separated compound statements.
__fixE711 | Private method to fix comparison with None.
__fixN804 | Private method to fix a wrong first argument of normal and class methods.
__fixN806 | Private method to fix a wrong first argument of static methods.
__fixReindent | Private method to fix a badly indented line.
__fixW291 | Private method to fix trailing whitespace.
__fixW292 | Private method to fix a missing newline at the end of file.
__fixW391 | Private method to fix trailing blank lines.
__fixW603 | Private method to fix the not equal notation.
__fixWhitespace | Private method to correct whitespace at the given offset.
__getID | Private method to get the ID for a deferred fix.
__getIndent | Private method to get the indentation string.
__getIndentWord | Private method to determine the indentation type.
__getLogical | Private method to get the logical line corresponding to the given position.
__multilineStringLines | Private method to determine the line numbers that are within multi line strings and these which are part of a documentation string.
finalize | Public method to apply all deferred fixes.
fixIssue | Public method to fix the fixable issues.
mutualStartswith | Local helper method to compare the beginnings of two strings against each other.
saveFile | Public method to save the modified file.

### Static Methods

None

#### CodeStyleFixer (Constructor)

CodeStyleFixer(filename, sourceLines, fixCodes, noFixCodes, maxLineLength, blankLines, inPlace, eol, backup=False, )

Constructor

filename (str)
  name of the file to be fixed
sourceLines (list of str)
  list of source lines including eol marker
fixCodes (str)
  list of codes to be fixed as a comma separated string
noFixCodes (str)
  list of codes not to be fixed as a comma separated string
maxLineLength (int)
  maximum allowed line length
blankLines (tuple of (int, int))
  tuple containg the number of blank lines before a top level class or function and before a method or nested class or function
inPlace (bool)
  flag indicating to modify the file in place
eol (str)
  end of line character(s)
backup (bool)
  flag indicating to create a backup before fixing anything

#### CodeStyleFixer.__codeMatch

__codeMatch(code)

Private method to check, if the code should be fixed.

code
  to check (string)

Return:
  flag indicating it should be fixed (boolean)

#### CodeStyleFixer.__findLogical

__findLogical()

Private method to extract the index of all the starts and ends of lines.

Return:
  tuple containing two lists of integer with start and end tuples of lines

#### CodeStyleFixer.__fixBlankLinesBefore

__fixBlankLinesBefore(code, line, pos, apply=False)

Private method to fix the need for blank lines before class, function and method definitions.

Codes: E301, E302, E303, E305, E306, E307, E308

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD111

__fixD111(code, line, pos)

Private method to fix docstring enclosed in wrong quotes.

Codes: D111

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD112

__fixD112(code, line, pos)

Private method to fix docstring 'r' in leading quotes.

Codes: D112

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD121

__fixD121(code, line, pos, apply=False)

Private method to fix a single line docstring on multiple lines.

Codes: D121

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD131

__fixD131(code, line, pos)

Private method to fix a docstring summary not ending with a period.

Codes: D131

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD141

__fixD141(code, line, pos, apply=False)

Private method to fix a function/method docstring preceded by a blank line.

Codes: D141

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD142

__fixD142(code, line, pos, apply=False)

Private method to fix a class docstring not preceded by a blank line.

Codes: D142

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD143

__fixD143(code, line, pos, apply=False)

Private method to fix a class docstring not followed by a blank line.

Codes: D143

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD144

__fixD144(code, line, pos, apply=False)

Private method to fix a docstring summary not followed by a blank line.

Codes: D144

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD145

__fixD145(code, line, pos, apply=False)

Private method to fix the last paragraph of a multi-line docstring not followed by a blank line.

Codes: D143

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD221

__fixD221(code, line, pos, apply=False)

Private method to fix leading and trailing quotes of docstring not on separate lines.

Codes: D221, D222

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD242

__fixD242(code, line, pos, apply=False)

Private method to fix a class or function/method docstring preceded by a blank line.

Codes: D242, D244

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD243

__fixD243(code, line, pos, apply=False)

Private method to fix a class or function/method docstring followed by a blank line.

Codes: D243, D245

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixD247

__fixD247(code, line, pos, apply=False)

Private method to fix a last paragraph of a docstring followed by a blank line.

Codes: D247

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE101

__fixE101(code, line, pos)

Private method to fix obsolete tab usage and indentation errors.

Codes: E101, E111, W191

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE121

__fixE121(code, line, pos, apply=False)

Private method to fix the indentation of continuation lines and closing brackets.

Codes: E121, E124

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE122

__fixE122(code, line, pos, apply=False)

Private method to fix a missing indentation of continuation lines.

Codes: E122

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE123

__fixE123(code, line, pos, apply=False)

Private method to fix the indentation of a closing bracket lines.

Codes: E123

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE125

__fixE125(code, line, pos, apply=False)

Private method to fix the indentation of continuation lines not distinguishable from next logical line.

Codes: E125

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE126

__fixE126(code, line, pos, apply=False)

Private method to fix over-indented/under-indented hanging indentation.

Codes: E126, E133

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE127

__fixE127(code, line, pos, apply=False)

Private method to fix over/under indented lines.

Codes: E127, E128

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE201

__fixE201(code, line, pos)

Private method to fix extraneous whitespace.

Codes: E201, E202, E203, E211

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE221

__fixE221(code, line, pos)

Private method to fix extraneous whitespace around operator or keyword.

Codes: E221, E222, E223, E224, E241, E242, E271, E272, E273, E274

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE225

__fixE225(code, line, pos)

Private method to fix extraneous whitespaces around operator.

Codes: E225, E226, E227, E228

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE231

__fixE231(code, line, pos)

Private method to fix missing whitespace after ',;:'.

Codes: E231

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE251

__fixE251(code, line, pos)

Private method to fix extraneous whitespace around keyword and default parameter equals.

Codes: E251

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE261

__fixE261(code, line, pos)

Private method to fix whitespace before or after inline comment.

Codes: E261, E262

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE304

__fixE304(code, line, pos, apply=False)

Private method to fix superfluous blank lines after a function decorator.

Codes: E304

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE401

__fixE401(code, line, pos, apply=False)

Private method to fix multiple imports on one line.

Codes: E401

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE501

__fixE501(code, line, pos, apply=False)

Private method to fix the long lines by breaking them.

Codes: E501

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE502

__fixE502(code, line, pos)

Private method to fix redundant backslash within brackets.

Codes: E502

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE701

__fixE701(code, line, pos, apply=False)

Private method to fix colon-separated compound statements.

Codes: E701

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE702

__fixE702(code, line, pos, apply=False)

Private method to fix semicolon-separated compound statements.

Codes: E702, E703

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixE711

__fixE711(code, line, pos)

Private method to fix comparison with None.

Codes: E711, E712

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixN804

__fixN804(code, line, pos, apply=False)

Private method to fix a wrong first argument of normal and class methods.

Codes: N804, N805

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixN806

__fixN806(code, line, pos, apply=False)

Private method to fix a wrong first argument of static methods.

Codes: N806

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line
apply (bool)
  flag indicating, that the fix should be applied

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixReindent

__fixReindent(line, pos, logical)

Private method to fix a badly indented line.

This is done by adding or removing from its initial indent only.

line
  line number of the issue (integer)
pos
  position inside line (integer)
logical
  logical line structure

Return:
  flag indicating a change was done (boolean)

Raises ValueError:
  raised to indicate a bad 'logical' parameter

#### CodeStyleFixer.__fixW291

__fixW291(code, line, pos)

Private method to fix trailing whitespace.

Codes: W291, W293

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixW292

__fixW292(code, line, pos)

Private method to fix a missing newline at the end of file.

Codes: W292

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixW391

__fixW391(code, line, pos)

Private method to fix trailing blank lines.

Codes: W391

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixW603

__fixW603(code, line, pos)

Private method to fix the not equal notation.

Codes: W603

code (str)
  code of the issue
line (int)
  line number of the issue
pos (int)
  position inside line

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, a list of arguments for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list or int, int)

#### CodeStyleFixer.__fixWhitespace

__fixWhitespace(line, offset, replacement)

Private method to correct whitespace at the given offset.

line
  line to be corrected (string)
offset
  offset within line (integer)
replacement
  replacement string (string)

Return:
  corrected line

#### CodeStyleFixer.__getID

__getID()

Private method to get the ID for a deferred fix.

Return:
  ID for a deferred fix (integer)

#### CodeStyleFixer.__getIndent

__getIndent(line)

Private method to get the indentation string.

line
  line to determine the indentation string from (string)

Return:
  indentation string (string)

#### CodeStyleFixer.__getIndentWord

__getIndentWord()

Private method to determine the indentation type.

Return:
  string to be used for an indentation (string)

#### CodeStyleFixer.__getLogical

__getLogical(line, pos)

Private method to get the logical line corresponding to the given position.

line
  line number of the issue (integer)
pos
  position inside line (integer)

Return:
  tuple of a tuple of two integers giving the start of the logical line, another tuple of two integers giving the end of the logical line and a list of strings with the original source lines

#### CodeStyleFixer.__multilineStringLines

__multilineStringLines()

Private method to determine the line numbers that are within multi line strings and these which are part of a documentation string.

Return:
  tuple of a set of line numbers belonging to a multi line string and a set of line numbers belonging to a multi line documentation string (tuple of two set of integer)

#### CodeStyleFixer.finalize

finalize()

Public method to apply all deferred fixes.

Return:
  dictionary containing the fix results

#### CodeStyleFixer.fixIssue

fixIssue(line, pos, code)

Public method to fix the fixable issues.

line (int)
  line number of the issue
pos (int)
  position inside line
code (str)
  code of the issue

Return:
  value indicating an applied/deferred fix (-1, 0, 1), a message code for the fix, arguments list for the message and an ID for a deferred fix

Return Type:
  tuple of (int, str, list, int)

#### CodeStyleFixer.mutualStartswith

mutualStartswith(b)

Local helper method to compare the beginnings of two strings against each other.

Return:
  flag indicating that one string starts with the other (boolean)

#### CodeStyleFixer.saveFile

saveFile(encoding)

Public method to save the modified file.

encoding
  encoding of the source file (string)

Return:
  error message on failure (tuple of str)

Up

## IndentationWrapper

Class used by fixers dealing with indentation.

Each instance operates on a single logical line.

### Derived from

None

### Class Attributes

SKIP_TOKENS

### Class Methods

None

### Methods

IndentationWrapper | Constructor
__buildTokensLogical | Private method to build a logical line from a list of tokens.
pep8Expected | Public method to replicate logic in pycodestyle.py, to know what level to indent things to.

### Static Methods

None

#### IndentationWrapper (Constructor)

IndentationWrapper(physical_lines)

Constructor

physical_lines
  list of physical lines to operate on (list of strings)

#### IndentationWrapper.__buildTokensLogical

__buildTokensLogical(tokens)

Private method to build a logical line from a list of tokens.

tokens
  list of tokens as generated by tokenize.generate_tokens

Return:
  logical line (string)

#### IndentationWrapper.pep8Expected

pep8Expected()

Public method to replicate logic in pycodestyle.py, to know what level to indent things to.

Return:
  list of lists, where each list represents valid indent levels for the line in question, relative from the initial indent. However, the first entry is the indent level which was expected.

Up

## LineShortener

Class used to shorten lines to a given maximum of characters.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

LineShortener | Constructor
__breakMultiline | Private method to break multi line strings.
__checkSyntax | Private method to check the syntax of the given code fragment.
__countUnbalancedBrackets | Private method to determine the number of unmatched open/close brackets.
__getIndent | Private method to get the indentation string.
__isProbablyInsideStringOrComment | Private method to check, if the given string might be inside a string or comment.
__lineShorteningRank | Private method to rank a candidate.
__normalizeMultiline | Private method to remove multiline-related code that will cause syntax error.
__shortenComment | Private method to shorten a comment line.
__shortenLine | Private method to shorten a line of code at an operator.
shorten | Public method to shorten the line wrapped by the class instance.

### Static Methods

None

#### LineShortener (Constructor)

LineShortener(curLine, prevLine, nextLine, maxLength=88, eol="\n", indentWord=" ", isDocString=False, )

Constructor

curLine
  text to work on (string)
prevLine
  line before the text to work on (string)
nextLine
  line after the text to work on (string)
maxLength
  maximum allowed line length (integer)
eol
  eond-of-line marker (string)
indentWord
  string used for indentation (string)
isDocString
  flag indicating that the line belongs to a documentation string (boolean)

#### LineShortener.__breakMultiline

__breakMultiline()

Private method to break multi line strings.

Return:
  tuple of the shortened line and the changed next line (string, string)

#### LineShortener.__checkSyntax

__checkSyntax(code)

Private method to check the syntax of the given code fragment.

code
  code fragment to check (string)

Return:
  flag indicating syntax is ok (boolean)

#### LineShortener.__countUnbalancedBrackets

__countUnbalancedBrackets(line)

Private method to determine the number of unmatched open/close brackets.

line
  line to work at (string)

Return:
  number of unmatched open/close brackets (integer)

#### LineShortener.__getIndent

__getIndent(line)

Private method to get the indentation string.

line
  line to determine the indentation string from (string)

Return:
  indentation string (string)

#### LineShortener.__isProbablyInsideStringOrComment

__isProbablyInsideStringOrComment(line, index)

Private method to check, if the given string might be inside a string or comment.

line
  line to check (string)
index
  position inside line to check (integer)

Return:
  flag indicating the possibility of being inside a string or comment

#### LineShortener.__lineShorteningRank

__lineShorteningRank(candidate)

Private method to rank a candidate.

candidate
  candidate line to rank (string)

Return:
  rank of the candidate (integer)

#### LineShortener.__normalizeMultiline

__normalizeMultiline(text)

Private method to remove multiline-related code that will cause syntax error.

text
  code line to work on (string)

Return:
  normalized code line (string)

#### LineShortener.__shortenComment

__shortenComment(isLast)

Private method to shorten a comment line.

isLast
  flag indicating, that the line is the last comment line (boolean)

Return:
  shortened comment line (string)

#### LineShortener.__shortenLine

__shortenLine(tokens, source, indent)

Private method to shorten a line of code at an operator.

tokens
  tokens of the line as generated by tokenize (list of token)
source
  code string to work at (string)
indent
  indentation string of the code line (string)

Return:
  list of candidates (list of string)

#### LineShortener.shorten

shorten()

Public method to shorten the line wrapped by the class instance.

Return:
  tuple of a flag indicating successful shortening, the shortened line and the changed next line (boolean, string, string)

Up

## Reindenter

Class to reindent badly-indented code to uniformly use four-space indentation.

Released to the public domain, by Tim Peters, 03 October 2000.

### Derived from

None

### Class Attributes

None

### Class Methods

None

### Methods

Reindenter | Constructor
__genStats | Private method to generate the re-indent statistics.
__getlspace | Private method to count number of leading blanks.
fixedLine | Public method to get a fixed line.
getline | Public method to get a line of text for tokenize.
run | Public method to run the re-indenter.

### Static Methods

None

#### Reindenter (Constructor)

Reindenter(sourceLines)

Constructor

sourceLines
  list of source lines including eol marker (list of string)

#### Reindenter.__genStats

__genStats(tokens)

Private method to generate the re-indent statistics.

tokens
  tokens generator (tokenize._tokenize)

Return:
  reference to the generated statistics

#### Reindenter.__getlspace

__getlspace(line)

Private method to count number of leading blanks.

line
  line to check (string)

Return:
  number of leading blanks (integer)

#### Reindenter.fixedLine

fixedLine(line)

Public method to get a fixed line.

line
  number of the line to retrieve (integer)

Return:
  fixed line (string)

#### Reindenter.getline

getline()

Public method to get a line of text for tokenize.

Return:
  line of text (string)

#### Reindenter.run

run()

Public method to run the re-indenter.

Return:
  flag indicating that a change was done (boolean)

Up