# eric3.Checks.Tabnanny

The Tab Nanny despises ambiguous indentation. She knows no mercy.

tabnanny -- Detection of ambiguous indentation

For the time being this module is intended to be called as a script. However it is possible to import it into an IDE and use the function check() described below.

Warning: The API provided by this module is likely to change in future releases; such changes may not be backward compatible.

This is a modified version to make the original tabnanny better suitable for being called from within the eric3 IDE.

Raises ValueError:
  The tokenize module is too old.

### Classes

NannyNag | Raised by tokeneater() if detecting an ambiguous indent.
Whitespace | Class implementing the whitespace checker.

### Functions

check | Private function to check one Python source file for whitespace related problems.
format_witnesses | Function to format the witnesses as a readable string.
tokeneater | Function implementing the token eater.

## NannyNag

Raised by tokeneater() if detecting an ambiguous indent. Captured and handled in check().

### Derived from

None

### Methods

NannyNag | Constructor
get_line | Method to retrieve the offending line.
get_lineno | Method to retrieve the line number.
get_msg | Method to retrieve the message.

### NannyNag (Constructor)

NannyNag(lineno, msg, line)

Constructor

lineno
  Line number of the ambiguous indent.
msg
  Descriptive message assigned to this problem.
line
  The offending source line.

### NannyNag.get_line

get_line()

Method to retrieve the offending line.

Returns:
  The line of code (string)

### NannyNag.get_lineno

get_lineno()

Method to retrieve the line number.

Returns:
  The line number (integer)

### NannyNag.get_msg

get_msg()

Method to retrieve the message.

Returns:
  The error message (string)

Up

## Whitespace

Class implementing the whitespace checker.

### Derived from

None

### Methods

Whitespace | Constructor
equal | Method to compare the indentation levels of two Whitespace objects for equality.
indent_level | Method to determine the indentation level.
less | Method to compare the indentation level against another Whitespace objects to be smaller.
longest_run_of_spaces | Method to calculate the length of longest contiguous run of spaces.
not_equal_witness | Method to calculate a tuple of witnessing tab size.
not_less_witness | Method to calculate a tuple of witnessing tab size.

### Whitespace (Constructor)

Whitespace(ws)

Constructor

ws
  The string to be checked.

### Whitespace.equal

equal(other)

Method to compare the indentation levels of two Whitespace objects for equality.

other
  Whitespace object to compare against.

Returns:
  True, if we compare equal against the other Whitespace object.

### Whitespace.indent_level

indent_level(tabsize)

Method to determine the indentation level.

tabsize
  The length of a tab stop. (integer)

Returns:
  indentation level (integer)

### Whitespace.less

less(other)

Method to compare the indentation level against another Whitespace objects to be smaller.

other
  Whitespace object to compare against.

Returns:
  True, if we compare less against the other Whitespace object.

### Whitespace.longest_run_of_spaces

longest_run_of_spaces()

Method to calculate the length of longest contiguous run of spaces.

Returns:
  The length of longest contiguous run of spaces (whether or not preceding a tab)

### Whitespace.not_equal_witness

not_equal_witness(other)

Method to calculate a tuple of witnessing tab size. Intended to be used after not self.equal(other) is known, in which case it will return at least one witnessing tab size.

other
  Whitespace object to calculate against.

Returns:
  A list of tuples (ts, i1, i2) such that i1 == self.indent_level(ts) != other.indent_level(ts) == i2.

### Whitespace.not_less_witness

not_less_witness(other)

Method to calculate a tuple of witnessing tab size. Intended to be used after not self.less(other is known, in which case it will return at least one witnessing tab size.

other
  Whitespace object to calculate against.

Returns:
  A list of tuples (ts, i1, i2) such that i1 == self.indent_level(ts) >= other.indent_level(ts) == i2.

Up

## check

check(file)

Private function to check one Python source file for whitespace related problems.

file
  source filename (string)

Returns:
  A tuple indicating status (1 = an error was found), the filename, the linenumber and the error message (boolean, string, string, string). The values are only valid, if the status equals 1.

Up

## format_witnesses

format_witnesses(w)

Function to format the witnesses as a readable string.

w
  A list of witnesses

Returns:
  A formated string of the witnesses.

Up

## tokeneater

tokeneater(type, token, start, end, line)

Function implementing the token eater. It is called by the tokenizer for every token encountered in the input stream.

type
  The type of the token.
token
  The token itself.
start
  The start of the token.
end
  The end of the token.
line
  The line of code containing the token.

Raises NannyNag:
  An indentation error has occured.

Up