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

object

### 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.
__fixD111 | Private method to fix docstring enclosed in wrong quotes.
__fixD112 | Private method to fix docstring 'r' or 'u' in leading quotes.
__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.
__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.
__fixE301 | Private method to fix the need for one blank line.
__fixE302 | Private method to fix the need for two blank lines.
__fixE303 | Private method to fix superfluous blank lines.
__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, inPlace, eol, backup=False)

Constructor

filename
  name of the file to be fixed (string)
sourceLines
  list of source lines including eol marker (list of string)
fixCodes
  list of codes to be fixed as a comma separated string (string)
noFixCodes
  list of codes not to be fixed as a comma separated string (string)
maxLineLength
  maximum allowed line length (integer)
inPlace
  flag indicating to modify the file in place (boolean)
eol
  end of line character(s) (string)
backup
  flag indicating to create a backup before fixing anything (boolean)

#### CodeStyleFixer.__codeMatch

__codeMatch(code)

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

code
  to check (string)

Returns:
  flag indicating it should be fixed (boolean)

#### CodeStyleFixer.__findLogical

__findLogical()

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

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

#### CodeStyleFixer.__fixD111

__fixD111(code, line, pos)

Private method to fix docstring enclosed in wrong quotes.

Codes: D111

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixD112

__fixD112(code, line, pos)

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

Codes: D112, D113

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixD131

__fixD131(code, line, pos)

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

Codes: D131

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixD141

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

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

Codes: D141

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixD142

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

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

Codes: D142

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixD143

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

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

Codes: D143

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixD144

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

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

Codes: D144

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE101

__fixE101(code, line, pos)

Private method to fix obsolete tab usage and indentation errors.

Codes: E101, E111, W191

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE121

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

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

Codes: E121, E124

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE122

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

Private method to fix a missing indentation of continuation lines.

Codes: E122

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE123

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

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

Codes: E123

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE126

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

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

Codes: E126, E133

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE127

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

Private method to fix over/under indented lines.

Codes: E127, E128

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE201

__fixE201(code, line, pos)

Private method to fix extraneous whitespace.

Codes: E201, E202, E203, E211

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE221

__fixE221(code, line, pos)

Private method to fix extraneous whitespace around operator or keyword.

Codes: E221, E222, E223, E224, E225, E226, E227, E228, E241, E242, E271, E272, E273, E274).

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE231

__fixE231(code, line, pos)

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

Codes: E231

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE251

__fixE251(code, line, pos)

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

Codes: E251

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE261

__fixE261(code, line, pos)

Private method to fix whitespace before or after inline comment.

Codes: E261, E262

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE301

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

Private method to fix the need for one blank line.

Codes: E301

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE302

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

Private method to fix the need for two blank lines.

Codes: E302

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE303

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

Private method to fix superfluous blank lines.

Codes: E303

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE304

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

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

Codes: E304

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE401

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

Private method to fix multiple imports on one line.

Codes: E401

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE501

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

Private method to fix the long lines by breaking them.

Codes: E501

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE502

__fixE502(code, line, pos)

Private method to fix redundant backslash within brackets.

Codes: E502

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE701

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

Private method to fix colon-separated compound statements.

Codes: E701

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE702

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

Private method to fix semicolon-separated compound statements.

Codes: E702, E703

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixE711

__fixE711(code, line, pos)

Private method to fix comparison with None.

Codes: E711, E712

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### 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
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixN806

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

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

Codes: N806

code
  code of the issue (string)
line
  line number of the issue (integer)
pos
  position inside line (integer)
apply=
  flag indicating, that the fix should be applied (boolean)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

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

Returns:
  flag indicating a change was done (boolean)

#### CodeStyleFixer.__fixW291

__fixW291(code, line, pos)

Private method to fix trailing whitespace.

Codes: W291, W293

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixW292

__fixW292(code, line, pos)

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

Codes: W292

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixW391

__fixW391(code, line, pos)

Private method to fix trailing blank lines.

Codes: W391

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.__fixW603

__fixW603(code, line, pos)

Private method to fix the not equal notation.

Codes: W603

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

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

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

Returns:
  corrected line

#### CodeStyleFixer.__getID

__getID()

Private method to get the ID for a deferred fix.

Returns:
  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)

Returns:
  indentation string (string)

#### CodeStyleFixer.__getIndentWord

__getIndentWord()

Private method to determine the indentation type.

Returns:
  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)

Returns:
  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.

Returns:
  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.

Returns:
  dictionary containing the fix results

#### CodeStyleFixer.fixIssue

fixIssue(line, pos, message)

Public method to fix the fixable issues.

line
  line number of issue (integer)
pos
  character position of issue (integer)
message
  message text (string)

Returns:
  value indicating an applied/deferred fix (-1, 0, 1), a message for the fix (string) and an ID for a deferred fix (integer)

#### CodeStyleFixer.mutualStartswith

mutualStartswith(b)

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

Returns:
  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)

Returns:
  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

object

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

Returns:
  logical line (string)

#### IndentationWrapper.pep8Expected

pep8Expected()

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

Returns:
  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

object

### 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=79, 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.

Returns:
  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)

Returns:
  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)

Returns:
  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)

Returns:
  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)

Returns:
  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)

Returns:
  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)

Returns:
  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)

Returns:
  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)

Returns:
  list of candidates (list of string)

#### LineShortener.shorten

shorten()

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

Returns:
  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

object

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

Returns:
  reference to the generated statistics

#### Reindenter.__getlspace

__getlspace(line)

Private method to count number of leading blanks.

line
  line to check (string)

Returns:
  number of leading blanks (integer)

#### Reindenter.fixedLine

fixedLine(line)

Public method to get a fixed line.

line
  number of the line to retrieve (integer)

Returns:
  fixed line (string)

#### Reindenter.getline

getline()

Public method to get a line of text for tokenize.

Returns:
  line of text (string)

#### Reindenter.run

run()

Public method to run the re-indenter.

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

Up