Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.Pep8Fixer.html

changeset 2885
7adb2d9880be
parent 2878
61042247f793
child 2897
45a5370f89a8
equal deleted inserted replaced
2884:b7380e6df302 2885:7adb2d9880be
34 <td>Class implementing a fixer for certain PEP 8 issues.</td> 34 <td>Class implementing a fixer for certain PEP 8 issues.</td>
35 </tr><tr> 35 </tr><tr>
36 <td><a href="#Pep8IndentationWrapper">Pep8IndentationWrapper</a></td> 36 <td><a href="#Pep8IndentationWrapper">Pep8IndentationWrapper</a></td>
37 <td>Class used by fixers dealing with indentation.</td> 37 <td>Class used by fixers dealing with indentation.</td>
38 </tr><tr> 38 </tr><tr>
39 <td><a href="#Pep8LineShortener">Pep8LineShortener</a></td>
40 <td>Class used to shorten lines to a given maximum of characters.</td>
41 </tr><tr>
39 <td><a href="#Pep8Reindenter">Pep8Reindenter</a></td> 42 <td><a href="#Pep8Reindenter">Pep8Reindenter</a></td>
40 <td>Class to reindent badly-indented code to uniformly use four-space indentation.</td> 43 <td>Class to reindent badly-indented code to uniformly use four-space indentation.</td>
41 </tr> 44 </tr>
42 </table> 45 </table>
43 <h3>Functions</h3> 46 <h3>Functions</h3>
124 <td>Private method to fix superfluous blank lines after a function decorator (E304).</td> 127 <td>Private method to fix superfluous blank lines after a function decorator (E304).</td>
125 </tr><tr> 128 </tr><tr>
126 <td><a href="#Pep8Fixer.__fixE401">__fixE401</a></td> 129 <td><a href="#Pep8Fixer.__fixE401">__fixE401</a></td>
127 <td>Private method to fix multiple imports on one line (E401).</td> 130 <td>Private method to fix multiple imports on one line (E401).</td>
128 </tr><tr> 131 </tr><tr>
132 <td><a href="#Pep8Fixer.__fixE501">__fixE501</a></td>
133 <td>Private method to fix the long lines by breaking them (E501).</td>
134 </tr><tr>
129 <td><a href="#Pep8Fixer.__fixE502">__fixE502</a></td> 135 <td><a href="#Pep8Fixer.__fixE502">__fixE502</a></td>
130 <td>Private method to fix redundant backslash within brackets (E502).</td> 136 <td>Private method to fix redundant backslash within brackets (E502).</td>
131 </tr><tr> 137 </tr><tr>
132 <td><a href="#Pep8Fixer.__fixE701">__fixE701</a></td> 138 <td><a href="#Pep8Fixer.__fixE701">__fixE701</a></td>
133 <td>Private method to fix colon-separated compund statements (E701).</td> 139 <td>Private method to fix colon-separated compund statements (E701).</td>
165 <td><a href="#Pep8Fixer.__getIndentWord">__getIndentWord</a></td> 171 <td><a href="#Pep8Fixer.__getIndentWord">__getIndentWord</a></td>
166 <td>Private method to determine the indentation type.</td> 172 <td>Private method to determine the indentation type.</td>
167 </tr><tr> 173 </tr><tr>
168 <td><a href="#Pep8Fixer.__getLogical">__getLogical</a></td> 174 <td><a href="#Pep8Fixer.__getLogical">__getLogical</a></td>
169 <td>Private method to get the logical line corresponding to the given position.</td> 175 <td>Private method to get the logical line corresponding to the given position.</td>
176 </tr><tr>
177 <td><a href="#Pep8Fixer.__multilineStringLines">__multilineStringLines</a></td>
178 <td>Private method to determine the line numbers that are within multi line strings and these which are part of a documentation string.</td>
170 </tr><tr> 179 </tr><tr>
171 <td><a href="#Pep8Fixer.fixIssue">fixIssue</a></td> 180 <td><a href="#Pep8Fixer.fixIssue">fixIssue</a></td>
172 <td>Public method to fix the fixable issues.</td> 181 <td>Public method to fix the fixable issues.</td>
173 </tr><tr> 182 </tr><tr>
174 <td><a href="#Pep8Fixer.mutualStartswith">mutualStartswith</a></td> 183 <td><a href="#Pep8Fixer.mutualStartswith">mutualStartswith</a></td>
235 Private method to apply all deferred fixes. 244 Private method to apply all deferred fixes.
236 </p><a NAME="Pep8Fixer.__findLogical" ID="Pep8Fixer.__findLogical"></a> 245 </p><a NAME="Pep8Fixer.__findLogical" ID="Pep8Fixer.__findLogical"></a>
237 <h4>Pep8Fixer.__findLogical</h4> 246 <h4>Pep8Fixer.__findLogical</h4>
238 <b>__findLogical</b>(<i></i>) 247 <b>__findLogical</b>(<i></i>)
239 <p> 248 <p>
240 Private method to extract the index of all the starts and ends of lines. 249 Private method to extract the index of all the starts and ends of
250 lines.
241 </p><dl> 251 </p><dl>
242 <dt>Returns:</dt> 252 <dt>Returns:</dt>
243 <dd> 253 <dd>
244 tuple containing two lists of integer with start and end tuples 254 tuple containing two lists of integer with start and end tuples
245 of lines 255 of lines
296 </dd> 306 </dd>
297 </dl><a NAME="Pep8Fixer.__fixE122" ID="Pep8Fixer.__fixE122"></a> 307 </dl><a NAME="Pep8Fixer.__fixE122" ID="Pep8Fixer.__fixE122"></a>
298 <h4>Pep8Fixer.__fixE122</h4> 308 <h4>Pep8Fixer.__fixE122</h4>
299 <b>__fixE122</b>(<i>code, line, pos, apply=False</i>) 309 <b>__fixE122</b>(<i>code, line, pos, apply=False</i>)
300 <p> 310 <p>
301 Private method to fix a missing indentation of continuation lines (E122). 311 Private method to fix a missing indentation of continuation lines
312 (E122).
302 </p><dl> 313 </p><dl>
303 <dt><i>code</i></dt> 314 <dt><i>code</i></dt>
304 <dd> 315 <dd>
305 code of the issue (string) 316 code of the issue (string)
306 </dd><dt><i>line</i></dt> 317 </dd><dt><i>line</i></dt>
322 </dd> 333 </dd>
323 </dl><a NAME="Pep8Fixer.__fixE123" ID="Pep8Fixer.__fixE123"></a> 334 </dl><a NAME="Pep8Fixer.__fixE123" ID="Pep8Fixer.__fixE123"></a>
324 <h4>Pep8Fixer.__fixE123</h4> 335 <h4>Pep8Fixer.__fixE123</h4>
325 <b>__fixE123</b>(<i>code, line, pos, apply=False</i>) 336 <b>__fixE123</b>(<i>code, line, pos, apply=False</i>)
326 <p> 337 <p>
327 Private method to fix the indentation of a closing bracket lines (E123). 338 Private method to fix the indentation of a closing bracket lines
339 (E123).
328 </p><dl> 340 </p><dl>
329 <dt><i>code</i></dt> 341 <dt><i>code</i></dt>
330 <dd> 342 <dd>
331 code of the issue (string) 343 code of the issue (string)
332 </dd><dt><i>line</i></dt> 344 </dd><dt><i>line</i></dt>
649 </dl><a NAME="Pep8Fixer.__fixE401" ID="Pep8Fixer.__fixE401"></a> 661 </dl><a NAME="Pep8Fixer.__fixE401" ID="Pep8Fixer.__fixE401"></a>
650 <h4>Pep8Fixer.__fixE401</h4> 662 <h4>Pep8Fixer.__fixE401</h4>
651 <b>__fixE401</b>(<i>code, line, pos, apply=False</i>) 663 <b>__fixE401</b>(<i>code, line, pos, apply=False</i>)
652 <p> 664 <p>
653 Private method to fix multiple imports on one line (E401). 665 Private method to fix multiple imports on one line (E401).
666 </p><dl>
667 <dt><i>code</i></dt>
668 <dd>
669 code of the issue (string)
670 </dd><dt><i>line</i></dt>
671 <dd>
672 line number of the issue (integer)
673 </dd><dt><i>pos</i></dt>
674 <dd>
675 position inside line (integer)
676 </dd><dt><i>apply=</i></dt>
677 <dd>
678 flag indicating, that the fix should be applied
679 (boolean)
680 </dd>
681 </dl><dl>
682 <dt>Returns:</dt>
683 <dd>
684 flag indicating an applied fix (boolean) and a message for
685 the fix (string)
686 </dd>
687 </dl><a NAME="Pep8Fixer.__fixE501" ID="Pep8Fixer.__fixE501"></a>
688 <h4>Pep8Fixer.__fixE501</h4>
689 <b>__fixE501</b>(<i>code, line, pos, apply=False</i>)
690 <p>
691 Private method to fix the long lines by breaking them (E501).
654 </p><dl> 692 </p><dl>
655 <dt><i>code</i></dt> 693 <dt><i>code</i></dt>
656 <dd> 694 <dd>
657 code of the issue (string) 695 code of the issue (string)
658 </dd><dt><i>line</i></dt> 696 </dd><dt><i>line</i></dt>
952 <dd> 990 <dd>
953 tuple of a tuple of two integers giving the start of the 991 tuple of a tuple of two integers giving the start of the
954 logical line, another tuple of two integers giving the end 992 logical line, another tuple of two integers giving the end
955 of the logical line and a list of strings with the original 993 of the logical line and a list of strings with the original
956 source lines 994 source lines
995 </dd>
996 </dl><a NAME="Pep8Fixer.__multilineStringLines" ID="Pep8Fixer.__multilineStringLines"></a>
997 <h4>Pep8Fixer.__multilineStringLines</h4>
998 <b>__multilineStringLines</b>(<i></i>)
999 <p>
1000 Private method to determine the line numbers that are within multi line
1001 strings and these which are part of a documentation string.
1002 </p><dl>
1003 <dt>Returns:</dt>
1004 <dd>
1005 tuple of a set of line numbers belonging to a multi line
1006 string and a set of line numbers belonging to a multi line
1007 documentation string (tuple of two set of integer)
957 </dd> 1008 </dd>
958 </dl><a NAME="Pep8Fixer.fixIssue" ID="Pep8Fixer.fixIssue"></a> 1009 </dl><a NAME="Pep8Fixer.fixIssue" ID="Pep8Fixer.fixIssue"></a>
959 <h4>Pep8Fixer.fixIssue</h4> 1010 <h4>Pep8Fixer.fixIssue</h4>
960 <b>fixIssue</b>(<i>line, pos, message</i>) 1011 <b>fixIssue</b>(<i>line, pos, message</i>)
961 <p> 1012 <p>
1074 Public method to replicate logic in pep8.py, to know what level to 1125 Public method to replicate logic in pep8.py, to know what level to
1075 indent things to. 1126 indent things to.
1076 </p><dl> 1127 </p><dl>
1077 <dt>Returns:</dt> 1128 <dt>Returns:</dt>
1078 <dd> 1129 <dd>
1079 list of lists, where each list represents valid indent levels for 1130 list of lists, where each list represents valid indent levels
1080 the line in question, relative from the initial indent. However, the 1131 for the line in question, relative from the initial indent. However,
1081 first entry is the indent level which was expected. 1132 the first entry is the indent level which was expected.
1133 </dd>
1134 </dl>
1135 <div align="right"><a href="#top">Up</a></div>
1136 <hr /><hr />
1137 <a NAME="Pep8LineShortener" ID="Pep8LineShortener"></a>
1138 <h2>Pep8LineShortener</h2>
1139 <p>
1140 Class used to shorten lines to a given maximum of characters.
1141 </p>
1142 <h3>Derived from</h3>
1143 object
1144 <h3>Class Attributes</h3>
1145 <table>
1146 <tr><td>None</td></tr>
1147 </table>
1148 <h3>Class Methods</h3>
1149 <table>
1150 <tr><td>None</td></tr>
1151 </table>
1152 <h3>Methods</h3>
1153 <table>
1154 <tr>
1155 <td><a href="#Pep8LineShortener.__init__">Pep8LineShortener</a></td>
1156 <td>Constructor</td>
1157 </tr><tr>
1158 <td><a href="#Pep8LineShortener.__breakMultiline">__breakMultiline</a></td>
1159 <td>Private method to break multi line strings.</td>
1160 </tr><tr>
1161 <td><a href="#Pep8LineShortener.__checkSyntax">__checkSyntax</a></td>
1162 <td>Private method to check the syntax of the given code fragment.</td>
1163 </tr><tr>
1164 <td><a href="#Pep8LineShortener.__countUnbalancedBrackets">__countUnbalancedBrackets</a></td>
1165 <td>Private method to determine the number of unmatched open/close brackets.</td>
1166 </tr><tr>
1167 <td><a href="#Pep8LineShortener.__getIndent">__getIndent</a></td>
1168 <td>Private method to get the indentation string.</td>
1169 </tr><tr>
1170 <td><a href="#Pep8LineShortener.__isProbablyInsideStringOrComment">__isProbablyInsideStringOrComment</a></td>
1171 <td>Private method to check, if the given string might be inside a string or comment.</td>
1172 </tr><tr>
1173 <td><a href="#Pep8LineShortener.__lineShorteningRank">__lineShorteningRank</a></td>
1174 <td>Private method to rank a candidate.</td>
1175 </tr><tr>
1176 <td><a href="#Pep8LineShortener.__normalizeMultiline">__normalizeMultiline</a></td>
1177 <td>Private method to remove multiline-related code that will cause syntax error.</td>
1178 </tr><tr>
1179 <td><a href="#Pep8LineShortener.__shortenComment">__shortenComment</a></td>
1180 <td>Private method to shorten a comment line.</td>
1181 </tr><tr>
1182 <td><a href="#Pep8LineShortener.__shortenLine">__shortenLine</a></td>
1183 <td>Private method to shorten a line of code at an operator.</td>
1184 </tr><tr>
1185 <td><a href="#Pep8LineShortener.shorten">shorten</a></td>
1186 <td>Public method to shorten the line wrapped by the class instance.</td>
1187 </tr>
1188 </table>
1189 <h3>Static Methods</h3>
1190 <table>
1191 <tr><td>None</td></tr>
1192 </table>
1193 <a NAME="Pep8LineShortener.__init__" ID="Pep8LineShortener.__init__"></a>
1194 <h4>Pep8LineShortener (Constructor)</h4>
1195 <b>Pep8LineShortener</b>(<i>curLine, prevLine, nextLine, maxLength=79, eol="\n", indentWord=" ", isDocString=False</i>)
1196 <p>
1197 Constructor
1198 </p><dl>
1199 <dt><i>curLine</i></dt>
1200 <dd>
1201 text to work on (string)
1202 </dd><dt><i>prevLine</i></dt>
1203 <dd>
1204 line before the text to work on (string)
1205 </dd><dt><i>nextLine</i></dt>
1206 <dd>
1207 line after the text to work on (string)
1208 </dd><dt><i>maxLength=</i></dt>
1209 <dd>
1210 maximum allowed line length (integer)
1211 </dd><dt><i>eol=</i></dt>
1212 <dd>
1213 eond-of-line marker (string)
1214 </dd><dt><i>indentWord=</i></dt>
1215 <dd>
1216 string used for indentation (string)
1217 </dd><dt><i>isDocString=</i></dt>
1218 <dd>
1219 flag indicating that the line belongs to
1220 a documentation string (boolean)
1221 </dd>
1222 </dl><a NAME="Pep8LineShortener.__breakMultiline" ID="Pep8LineShortener.__breakMultiline"></a>
1223 <h4>Pep8LineShortener.__breakMultiline</h4>
1224 <b>__breakMultiline</b>(<i></i>)
1225 <p>
1226 Private method to break multi line strings.
1227 </p><dl>
1228 <dt>Returns:</dt>
1229 <dd>
1230 tuple of the shortened line and the changed next line
1231 (string, string)
1232 </dd>
1233 </dl><a NAME="Pep8LineShortener.__checkSyntax" ID="Pep8LineShortener.__checkSyntax"></a>
1234 <h4>Pep8LineShortener.__checkSyntax</h4>
1235 <b>__checkSyntax</b>(<i>code</i>)
1236 <p>
1237 Private method to check the syntax of the given code fragment.
1238 </p><dl>
1239 <dt><i>code</i></dt>
1240 <dd>
1241 code fragment to check (string)
1242 </dd>
1243 </dl><dl>
1244 <dt>Returns:</dt>
1245 <dd>
1246 flag indicating syntax is ok (boolean)
1247 </dd>
1248 </dl><a NAME="Pep8LineShortener.__countUnbalancedBrackets" ID="Pep8LineShortener.__countUnbalancedBrackets"></a>
1249 <h4>Pep8LineShortener.__countUnbalancedBrackets</h4>
1250 <b>__countUnbalancedBrackets</b>(<i>line</i>)
1251 <p>
1252 Private method to determine the number of unmatched open/close
1253 brackets.
1254 </p><dl>
1255 <dt><i>line</i></dt>
1256 <dd>
1257 line to work at (string)
1258 </dd>
1259 </dl><dl>
1260 <dt>Returns:</dt>
1261 <dd>
1262 number of unmatched open/close brackets (integer)
1263 </dd>
1264 </dl><a NAME="Pep8LineShortener.__getIndent" ID="Pep8LineShortener.__getIndent"></a>
1265 <h4>Pep8LineShortener.__getIndent</h4>
1266 <b>__getIndent</b>(<i>line</i>)
1267 <p>
1268 Private method to get the indentation string.
1269 </p><dl>
1270 <dt><i>line</i></dt>
1271 <dd>
1272 line to determine the indentation string from (string)
1273 </dd>
1274 </dl><dl>
1275 <dt>Returns:</dt>
1276 <dd>
1277 indentation string (string)
1278 </dd>
1279 </dl><a NAME="Pep8LineShortener.__isProbablyInsideStringOrComment" ID="Pep8LineShortener.__isProbablyInsideStringOrComment"></a>
1280 <h4>Pep8LineShortener.__isProbablyInsideStringOrComment</h4>
1281 <b>__isProbablyInsideStringOrComment</b>(<i>line, index</i>)
1282 <p>
1283 Private method to check, if the given string might be inside a string
1284 or comment.
1285 </p><dl>
1286 <dt><i>line</i></dt>
1287 <dd>
1288 line to check (string)
1289 </dd><dt><i>index</i></dt>
1290 <dd>
1291 position inside line to check (integer)
1292 </dd>
1293 </dl><dl>
1294 <dt>Returns:</dt>
1295 <dd>
1296 flag indicating the possibility of being inside a string
1297 or comment
1298 </dd>
1299 </dl><a NAME="Pep8LineShortener.__lineShorteningRank" ID="Pep8LineShortener.__lineShorteningRank"></a>
1300 <h4>Pep8LineShortener.__lineShorteningRank</h4>
1301 <b>__lineShorteningRank</b>(<i>candidate</i>)
1302 <p>
1303 Private method to rank a candidate.
1304 </p><dl>
1305 <dt><i>candidate</i></dt>
1306 <dd>
1307 candidate line to rank (string)
1308 </dd>
1309 </dl><dl>
1310 <dt>Returns:</dt>
1311 <dd>
1312 rank of the candidate (integer)
1313 </dd>
1314 </dl><a NAME="Pep8LineShortener.__normalizeMultiline" ID="Pep8LineShortener.__normalizeMultiline"></a>
1315 <h4>Pep8LineShortener.__normalizeMultiline</h4>
1316 <b>__normalizeMultiline</b>(<i>text</i>)
1317 <p>
1318 Private method to remove multiline-related code that will cause syntax
1319 error.
1320 </p><dl>
1321 <dt><i>line</i></dt>
1322 <dd>
1323 code line to work on (string)
1324 </dd>
1325 </dl><dl>
1326 <dt>Returns:</dt>
1327 <dd>
1328 normalized code line (string)
1329 </dd>
1330 </dl><a NAME="Pep8LineShortener.__shortenComment" ID="Pep8LineShortener.__shortenComment"></a>
1331 <h4>Pep8LineShortener.__shortenComment</h4>
1332 <b>__shortenComment</b>(<i>isLast</i>)
1333 <p>
1334 Private method to shorten a comment line.
1335 </p><dl>
1336 <dt><i>isLast</i></dt>
1337 <dd>
1338 flag indicating, that the line is the last comment line
1339 (boolean)
1340 </dd>
1341 </dl><dl>
1342 <dt>Returns:</dt>
1343 <dd>
1344 shortened comment line (string)
1345 </dd>
1346 </dl><a NAME="Pep8LineShortener.__shortenLine" ID="Pep8LineShortener.__shortenLine"></a>
1347 <h4>Pep8LineShortener.__shortenLine</h4>
1348 <b>__shortenLine</b>(<i>tokens, source, indent</i>)
1349 <p>
1350 Private method to shorten a line of code at an operator.
1351 </p><dl>
1352 <dt><i>tokens</i></dt>
1353 <dd>
1354 tokens of the line as generated by tokenize
1355 (list of token)
1356 </dd><dt><i>source</i></dt>
1357 <dd>
1358 code string to work at (string)
1359 </dd><dt><i>indent</i></dt>
1360 <dd>
1361 indentation string of the code line (string)
1362 </dd>
1363 </dl><dl>
1364 <dt>Returns:</dt>
1365 <dd>
1366 list of candidates (list of string)
1367 </dd>
1368 </dl><a NAME="Pep8LineShortener.shorten" ID="Pep8LineShortener.shorten"></a>
1369 <h4>Pep8LineShortener.shorten</h4>
1370 <b>shorten</b>(<i></i>)
1371 <p>
1372 Public method to shorten the line wrapped by the class instance.
1373 </p><dl>
1374 <dt>Returns:</dt>
1375 <dd>
1376 tuple of a flag indicating successful shortening, the
1377 shortened line and the changed next line (boolean, string, string)
1082 </dd> 1378 </dd>
1083 </dl> 1379 </dl>
1084 <div align="right"><a href="#top">Up</a></div> 1380 <div align="right"><a href="#top">Up</a></div>
1085 <hr /><hr /> 1381 <hr /><hr />
1086 <a NAME="Pep8Reindenter" ID="Pep8Reindenter"></a> 1382 <a NAME="Pep8Reindenter" ID="Pep8Reindenter"></a>
1087 <h2>Pep8Reindenter</h2> 1383 <h2>Pep8Reindenter</h2>
1088 <p> 1384 <p>
1089 Class to reindent badly-indented code to uniformly use four-space indentation. 1385 Class to reindent badly-indented code to uniformly use four-space
1386 indentation.
1090 </p><p> 1387 </p><p>
1091 Released to the public domain, by Tim Peters, 03 October 2000. 1388 Released to the public domain, by Tim Peters, 03 October 2000.
1092 </p> 1389 </p>
1093 <h3>Derived from</h3> 1390 <h3>Derived from</h3>
1094 object 1391 object

eric ide

mercurial