# 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 (str)
  to check

Return:
  flag indicating it should be fixed

Return Type:
  bool

#### 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

Return Type:
  tuple of ([int, int], [int, int])

#### 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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (unused)

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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (unused)

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 (unused)
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 (unused)
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 (unused)
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 (unused)
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 (unused)
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 (unused)
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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (unused)
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 (int)
  line number of the issue
_pos (int)
  position inside line (unused)
logical (str)
  logical line structure

Return:
  flag indicating a change was done

Return Type:
  bool

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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (unused)
line (int)
  line number of the issue
_pos (int)
  position inside line (unused)

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 (str)
  line to be corrected
offset (int)
  offset within line
replacement (str)
  replacement string

Return:
  corrected line

Return Type:
  str

#### CodeStyleFixer.__getID

__getID()

Private method to get the ID for a deferred fix.

Return:
  ID for a deferred fix

Return Type:
  int

#### CodeStyleFixer.__getIndent

__getIndent(line)

Private method to get the indentation string.

line (str)
  line to determine the indentation string from

Return:
  indentation string

Return Type:
  str

#### CodeStyleFixer.__getIndentWord

__getIndentWord()

Private method to determine the indentation type.

Return:
  string to be used for an indentation

Return Type:
  str

#### CodeStyleFixer.__getLogical

__getLogical(line, pos)

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

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

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

Return Type:
  tuple of ((int, int), (int, int), [str])

#### 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

Return Type:
  tuple of (set of int, set of int)

#### CodeStyleFixer.finalize

finalize()

Public method to apply all deferred fixes.

Return:
  dictionary containing the fix results

Return Type:
  dict

#### 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

Return Type:
  bool

#### CodeStyleFixer.saveFile

saveFile(encoding)

Public method to save the modified file.

encoding (str)
  encoding of the source file

Return:
  error message on failure

Return Type:
  tuple of (str, [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 str)
  list of physical lines to operate on

#### IndentationWrapper.__buildTokensLogical

__buildTokensLogical(tokens)

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

tokens (list of Token)
  list of tokens as generated by tokenize.generate_tokens

Return:
  logical line

Return Type:
  str

#### 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.

Return Type:
  list of list

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 (str)
  text to work on
prevLine (str)
  line before the text to work on
nextLine (str)
  line after the text to work on
maxLength (int)
  maximum allowed line length
eol (str)
  eond-of-line marker
indentWord (str)
  string used for indentation
isDocString (bool)
  flag indicating that the line belongs to a documentation string

#### LineShortener.__breakMultiline

__breakMultiline()

Private method to break multi line strings.

Return:
  tuple of the shortened line and the changed next line

Return Type:
  tuple of (str, str)

#### LineShortener.__checkSyntax

__checkSyntax(code)

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

code (str)
  code fragment to check

Return:
  flag indicating syntax is ok

Return Type:
  bool

#### LineShortener.__countUnbalancedBrackets

__countUnbalancedBrackets(line)

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

line (str)
  line to work at

Return:
  number of unmatched open/close brackets

Return Type:
  int

#### LineShortener.__getIndent

__getIndent(line)

Private method to get the indentation string.

line (str)
  line to determine the indentation string from

Return:
  indentation string

Return Type:
  str

#### LineShortener.__isProbablyInsideStringOrComment

__isProbablyInsideStringOrComment(line, index)

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

line (str)
  line to check
index (int)
  position inside line to check

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

Return Type:
  bool

#### LineShortener.__lineShorteningRank

__lineShorteningRank(candidate)

Private method to rank a candidate.

candidate (str)
  candidate line to rank

Return:
  rank of the candidate

Return Type:
  int

#### LineShortener.__normalizeMultiline

__normalizeMultiline(text)

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

text (str)
  code line to work on

Return:
  normalized code line

Return Type:
  str

#### LineShortener.__shortenComment

__shortenComment(isLast)

Private method to shorten a comment line.

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

Return:
  shortened comment line

Return Type:
  str

#### LineShortener.__shortenLine

__shortenLine(tokens, source, indent)

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

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

Return:
  list of candidates

Return Type:
  list of str

#### 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

Return Type:
  tuple of (bool, str, str)

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 str)
  list of source lines including eol marker

#### Reindenter.__genStats

__genStats(tokens)

Private method to generate the re-indent statistics.

tokens (function)
  tokens generator (tokenize._tokenize)

Return:
  reference to the generated statistics

Return Type:
  dict

#### Reindenter.__getlspace

__getlspace(line)

Private method to count number of leading blanks.

line (str)
  line to check

Return:
  number of leading blanks

Return Type:
  int

#### Reindenter.fixedLine

fixedLine(line)

Public method to get a fixed line.

line (int)
  number of the line to retrieve

Return:
  fixed line

Return Type:
  str

#### Reindenter.getline

getline()

Public method to get a line of text for tokenize.

Return:
  line of text

Return Type:
  str

#### Reindenter.run

run()

Public method to run the re-indenter.

Return:
  flag indicating that a change was done

Return Type:
  bool

Up