# eric6.Plugins.CheckerPlugins.Tabnanny.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 eric6 IDE.

Raises ValueError:
  The tokenize module is too old.

### Global Attributes

__all__
__version__

### Classes

NannyNag | Class implementing an exception for indentation issues.
Whitespace | Class implementing the whitespace checker.

### Functions

__check | Private function to check one Python source file for whitespace related problems.
batchCheck | Module function to check a batch of files for whitespace related problems.
check | Private function to check one Python source file for whitespace related problems.
format_witnesses | Function to format the witnesses as a readable string.
initBatchService | Initialize the batch service and return the entry point.
initService | Initialize the service and return the entry point.
process_tokens | Function processing all tokens generated by a tokenizer run.
worker | Module function acting as the parallel worker for the style check.

## NannyNag

Class implementing an exception for indentation issues.

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

### Derived from

Exception

### Class Attributes

None

### Class Methods

None

### Methods

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

### Static Methods

None

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

Public method to retrieve the offending line.

Returns:
  The line of code (string)

#### NannyNag.get_lineno

get_lineno()

Public method to retrieve the line number.

Returns:
  The line number (integer)

#### NannyNag.get_msg

get_msg()

Public method to retrieve the message.

Returns:
  The error message (string)

Up

## Whitespace

Class implementing the whitespace checker.

### Derived from

object

### Class Attributes

None

### Class Methods

None

### Methods

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

### Static Methods

None

#### Whitespace (Constructor)

Whitespace(ws)

Constructor

ws
  The string to be checked.

#### Whitespace.equal

equal(other)

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

Public method to determine the indentation level.

tabsize
  The length of a tab stop. (integer)

Returns:
  indentation level (integer)

#### Whitespace.less

less(other)

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

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

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

Public 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, text="")

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

file
  source filename (string)
text
  source text (string)

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

Up

## batchCheck

batchCheck(argumentsList, send, fx, cancelled, maxProcesses=0)

Module function to check a batch of files for whitespace related problems.

argumentsList (list)
  list of arguments tuples as given for check
send (func)
  reference to send function
fx (str)
  registered service name
cancelled (func)
  reference to function checking for a cancellation
maxProcesses (int)
  number of processes to be used

Up

## check

check(file, text="")

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

file
  source filename (string)
text
  source text (string)

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

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

## initBatchService

initBatchService()

Initialize the batch service and return the entry point.

Returns:
  the entry point for the background client (function)

Up

## initService

initService()

Initialize the service and return the entry point.

Returns:
  the entry point for the background client (function)

Up

## process_tokens

process_tokens(tokens)

Function processing all tokens generated by a tokenizer run.

tokens
  list of tokens

Raises NannyNag:
  raised to indicate an indentation error

Up

## worker

worker(inputQueue, outputQueue)

Module function acting as the parallel worker for the style check.

inputQueue
  input queue (multiprocessing.Queue)
outputQueue
  output queue (multiprocessing.Queue)

Up