eric4.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 eric4 IDE.

Raises ValueError:
The tokenize module is too old.

Global Attributes

__all__
__version__

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.
process_tokens Function processing all tokens generated by a tokenizer run.


NannyNag

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 Method to retrieve the offending line.
get_lineno Method to retrieve the line number.
get_msg 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()

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

object

Class Attributes

None

Class Methods

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.

Static Methods

None

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


process_tokens

process_tokens(tokens)

Function processing all tokens generated by a tokenizer run.

tokens
list of tokens
Up