1
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
2
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
4
<title>eric3.Checks.Tabnanny</title>
6
<body bgcolor="#FFFFFF"><a NAME="top" ID="top"></a>
7
<h1><font color="#0000FF">eric3.Checks.Tabnanny</font></h1>
9
The Tab Nanny despises ambiguous indentation. She knows no mercy.
11
tabnanny -- Detection of ambiguous indentation
13
For the time being this module is intended to be called as a script.
14
However it is possible to import it into an IDE and use the function
15
check() described below.
17
Warning: The API provided by this module is likely to change in future
18
releases; such changes may not be backward compatible.
20
This is a modified version to make the original tabnanny better suitable
21
for being called from within the eric3 IDE.
23
<dt>Raises <b>ValueError</b>:</dt>
25
The tokenize module is too old.
28
<h3><font color="#FF0000">Classes</font></h3>
31
<td><a href="#NannyNag">NannyNag</a></td>
32
<td>Raised by tokeneater() if detecting an ambiguous indent.</td>
34
<td><a href="#Whitespace">Whitespace</a></td>
35
<td>Class implementing the whitespace checker.</td>
38
<h3><font color="#FF0000">Functions</font></h3>
41
<td><a href="#check">check</a></td>
42
<td>Private function to check one Python source file for whitespace related problems.</td>
44
<td><a href="#format_witnesses">format_witnesses</a></td>
45
<td>Function to format the witnesses as a readable string.</td>
47
<td><a href="#tokeneater">tokeneater</a></td>
48
<td>Function implementing the token eater.</td>
52
<a NAME="NannyNag" ID="NannyNag"></a>
53
<h2><font color="#0000FF">NannyNag</font></h2>
55
Raised by tokeneater() if detecting an ambiguous indent.
56
Captured and handled in check().
58
<h3><font color="#FF0000">Derived from</font></h3>
60
<h3><font color="#FF0000">Methods</font></h3>
63
<td><a href="#NannyNag.__init__">NannyNag</a></td>
66
<td><a href="#NannyNag.get_line">get_line</a></td>
67
<td>Method to retrieve the offending line.</td>
69
<td><a href="#NannyNag.get_lineno">get_lineno</a></td>
70
<td>Method to retrieve the line number.</td>
72
<td><a href="#NannyNag.get_msg">get_msg</a></td>
73
<td>Method to retrieve the message.</td>
76
<p><a NAME="NannyNag.__init__" ID="NannyNag__init__"></a>
77
<h3><font color="#0000FF">NannyNag (Constructor)</font></h3>
78
<b>NannyNag</b>(<i>lineno, msg, line</i>)
82
<dt><i>lineno</i></dt>
84
Line number of the ambiguous indent.
85
</dd><dt><i>msg</i></dt>
87
Descriptive message assigned to this problem.
88
</dd><dt><i>line</i></dt>
90
The offending source line.
92
</dl><a NAME="NannyNag.get_line" ID="NannyNagget_line"></a>
93
<h3><font color="#0000FF">NannyNag.get_line</font></h3>
94
<b>get_line</b>(<i></i>)
96
Method to retrieve the offending line.
100
The line of code (string)
102
</dl><a NAME="NannyNag.get_lineno" ID="NannyNagget_lineno"></a>
103
<h3><font color="#0000FF">NannyNag.get_lineno</font></h3>
104
<b>get_lineno</b>(<i></i>)
106
Method to retrieve the line number.
110
The line number (integer)
112
</dl><a NAME="NannyNag.get_msg" ID="NannyNagget_msg"></a>
113
<h3><font color="#0000FF">NannyNag.get_msg</font></h3>
114
<b>get_msg</b>(<i></i>)
116
Method to retrieve the message.
120
The error message (string)
123
<div align="right"><a href="#top">Up</a></div>
125
<a NAME="Whitespace" ID="Whitespace"></a>
126
<h2><font color="#0000FF">Whitespace</font></h2>
128
Class implementing the whitespace checker.
130
<h3><font color="#FF0000">Derived from</font></h3>
132
<h3><font color="#FF0000">Methods</font></h3>
135
<td><a href="#Whitespace.__init__">Whitespace</a></td>
138
<td><a href="#Whitespace.equal">equal</a></td>
139
<td>Method to compare the indentation levels of two Whitespace objects for equality.</td>
141
<td><a href="#Whitespace.indent_level">indent_level</a></td>
142
<td>Method to determine the indentation level.</td>
144
<td><a href="#Whitespace.less">less</a></td>
145
<td>Method to compare the indentation level against another Whitespace objects to be smaller.</td>
147
<td><a href="#Whitespace.longest_run_of_spaces">longest_run_of_spaces</a></td>
148
<td>Method to calculate the length of longest contiguous run of spaces.</td>
150
<td><a href="#Whitespace.not_equal_witness">not_equal_witness</a></td>
151
<td>Method to calculate a tuple of witnessing tab size.</td>
153
<td><a href="#Whitespace.not_less_witness">not_less_witness</a></td>
154
<td>Method to calculate a tuple of witnessing tab size.</td>
157
<p><a NAME="Whitespace.__init__" ID="Whitespace__init__"></a>
158
<h3><font color="#0000FF">Whitespace (Constructor)</font></h3>
159
<b>Whitespace</b>(<i>ws</i>)
165
The string to be checked.
167
</dl><a NAME="Whitespace.equal" ID="Whitespaceequal"></a>
168
<h3><font color="#0000FF">Whitespace.equal</font></h3>
169
<b>equal</b>(<i>other</i>)
171
Method to compare the indentation levels of two Whitespace objects for equality.
173
<dt><i>other</i></dt>
175
Whitespace object to compare against.
180
True, if we compare equal against the other Whitespace object.
182
</dl><a NAME="Whitespace.indent_level" ID="Whitespaceindent_level"></a>
183
<h3><font color="#0000FF">Whitespace.indent_level</font></h3>
184
<b>indent_level</b>(<i>tabsize</i>)
186
Method to determine the indentation level.
188
<dt><i>tabsize</i></dt>
190
The length of a tab stop. (integer)
195
indentation level (integer)
197
</dl><a NAME="Whitespace.less" ID="Whitespaceless"></a>
198
<h3><font color="#0000FF">Whitespace.less</font></h3>
199
<b>less</b>(<i>other</i>)
201
Method to compare the indentation level against another Whitespace objects to be smaller.
203
<dt><i>other</i></dt>
205
Whitespace object to compare against.
210
True, if we compare less against the other Whitespace object.
212
</dl><a NAME="Whitespace.longest_run_of_spaces" ID="Whitespacelongest_run_of_spaces"></a>
213
<h3><font color="#0000FF">Whitespace.longest_run_of_spaces</font></h3>
214
<b>longest_run_of_spaces</b>(<i></i>)
216
Method to calculate the length of longest contiguous run of spaces.
220
The length of longest contiguous run of spaces (whether or not
223
</dl><a NAME="Whitespace.not_equal_witness" ID="Whitespacenot_equal_witness"></a>
224
<h3><font color="#0000FF">Whitespace.not_equal_witness</font></h3>
225
<b>not_equal_witness</b>(<i>other</i>)
227
Method to calculate a tuple of witnessing tab size.
229
Intended to be used after not self.equal(other) is known, in which
230
case it will return at least one witnessing tab size.
232
<dt><i>other</i></dt>
234
Whitespace object to calculate against.
239
A list of tuples (ts, i1, i2) such that
240
i1 == self.indent_level(ts) != other.indent_level(ts) == i2.
242
</dl><a NAME="Whitespace.not_less_witness" ID="Whitespacenot_less_witness"></a>
243
<h3><font color="#0000FF">Whitespace.not_less_witness</font></h3>
244
<b>not_less_witness</b>(<i>other</i>)
246
Method to calculate a tuple of witnessing tab size.
248
Intended to be used after not self.less(other is known, in which
249
case it will return at least one witnessing tab size.
251
<dt><i>other</i></dt>
253
Whitespace object to calculate against.
258
A list of tuples (ts, i1, i2) such that
259
i1 == self.indent_level(ts) >= other.indent_level(ts) == i2.
262
<div align="right"><a href="#top">Up</a></div>
264
<a NAME="check" ID="check"></a>
265
<h2><font color="#0000FF">check</font></h2>
266
<b>check</b>(<i>file</i>)
268
Private function to check one Python source file for whitespace related problems.
272
source filename (string)
277
A tuple indicating status (1 = an error was found), the
278
filename, the linenumber and the error message
279
(boolean, string, string, string). The values are only
280
valid, if the status equals 1.
283
<div align="right"><a href="#top">Up</a></div>
285
<a NAME="format_witnesses" ID="format_witnesses"></a>
286
<h2><font color="#0000FF">format_witnesses</font></h2>
287
<b>format_witnesses</b>(<i>w</i>)
289
Function to format the witnesses as a readable string.
298
A formated string of the witnesses.
301
<div align="right"><a href="#top">Up</a></div>
303
<a NAME="tokeneater" ID="tokeneater"></a>
304
<h2><font color="#0000FF">tokeneater</font></h2>
305
<b>tokeneater</b>(<i>type, token, start, end, line</i>)
307
Function implementing the token eater.
309
It is called by the tokenizer for every token encountered
314
The type of the token.
315
</dd><dt><i>token</i></dt>
318
</dd><dt><i>start</i></dt>
320
The start of the token.
321
</dd><dt><i>end</i></dt>
323
The end of the token.
324
</dd><dt><i>line</i></dt>
326
The line of code containing the token.
329
<dt>Raises <b>NannyNag</b>:</dt>
331
An indentation error has occured.
334
<div align="right"><a href="#top">Up</a></div>
b'\\ No newline at end of file'