Thu, 27 Feb 2025 14:42:39 +0100
Code Style Checkers
- Refactored the various code style checkers for better maintainability.
<!DOCTYPE html> <html><head> <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.MiscellaneousChecker</title> <meta charset="UTF-8"> <link rel="stylesheet" href="styles.css"> </head> <body> <a NAME="top" ID="top"></a> <h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.MiscellaneousChecker</h1> <p> Module implementing a checker for miscellaneous checks. </p> <h3>Global Attributes</h3> <table> <tr><td>None</td></tr> </table> <h3>Classes</h3> <table> <tr> <td><a href="#MiscellaneousChecker">MiscellaneousChecker</a></td> <td>Class implementing a checker for miscellaneous checks.</td> </tr> </table> <h3>Functions</h3> <table> <tr> <td><a href="#pairwise">pairwise</a></td> <td></td> </tr> </table> <hr /> <hr /> <a NAME="MiscellaneousChecker" ID="MiscellaneousChecker"></a> <h2>MiscellaneousChecker</h2> <p> Class implementing a checker for miscellaneous checks. </p> <h3>Derived from</h3> CodeStyleTopicChecker <h3>Class Attributes</h3> <table> <tr><td>BuiltinsWhiteList</td></tr> <tr><td>Category</td></tr> <tr><td>Codes</td></tr> <tr><td>FormatFieldRegex</td></tr> <tr><td>Formatter</td></tr> </table> <h3>Class Methods</h3> <table> <tr><td>None</td></tr> </table> <h3>Methods</h3> <table> <tr> <td><a href="#MiscellaneousChecker.__init__">MiscellaneousChecker</a></td> <td>Constructor</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkBugBear">__checkBugBear</a></td> <td>Private method for bugbear checks.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkBuiltins">__checkBuiltins</a></td> <td>Private method to check, if built-ins are shadowed.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkCoding">__checkCoding</a></td> <td>Private method to check the presence of a coding line and valid encodings.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkCommentedCode">__checkCommentedCode</a></td> <td>Private method to check for commented code.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkComprehensions">__checkComprehensions</a></td> <td>Private method to check some comprehension related things.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkCopyright">__checkCopyright</a></td> <td>Private method to check the presence of a copyright statement.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkDateTime">__checkDateTime</a></td> <td>Private method to check use of naive datetime functions.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkDefaultMatchCase">__checkDefaultMatchCase</a></td> <td>Private method to check the default match case.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkDictWithSortedKeys">__checkDictWithSortedKeys</a></td> <td>Private method to check, if dictionary keys appear in sorted order.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkExplicitStringConcat">__checkExplicitStringConcat</a></td> <td>Private method to check for explicitly concatenated strings.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkFormatString">__checkFormatString</a></td> <td>Private method to check string format strings.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkFuture">__checkFuture</a></td> <td>Private method to check the __future__ imports.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkGettext">__checkGettext</a></td> <td>Private method to check the 'gettext' import statement.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkImplicitStringConcat">__checkImplicitStringConcat</a></td> <td>Private method to check for implicitly concatenated strings.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkLineContinuation">__checkLineContinuation</a></td> <td>Private method to check line continuation using backslash.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkPep3101">__checkPep3101</a></td> <td>Private method to check for old style string formatting.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkPrintStatements">__checkPrintStatements</a></td> <td>Private method to check for print statements.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkProperties">__checkProperties</a></td> <td>Private method to check for issue with property related methods.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkReturn">__checkReturn</a></td> <td>Private method to check return statements.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkSysVersion">__checkSysVersion</a></td> <td>Private method to check the use of sys.version and sys.version_info.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__checkTuple">__checkTuple</a></td> <td>Private method to check for one element tuples.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__dictShouldBeChecked">__dictShouldBeChecked</a></td> <td>Private function to test, if the node should be checked.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__getCoding">__getCoding</a></td> <td>Private method to get the defined coding of the source.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__getFields">__getFields</a></td> <td>Private method to extract the format field information.</td> </tr> <tr> <td><a href="#MiscellaneousChecker.__isImplicitStringConcat">__isImplicitStringConcat</a></td> <td>Private method to check, if the given strings indicate an implicit string concatenation.</td> </tr> </table> <h3>Static Methods</h3> <table> <tr><td>None</td></tr> </table> <a NAME="MiscellaneousChecker.__init__" ID="MiscellaneousChecker.__init__"></a> <h4>MiscellaneousChecker (Constructor)</h4> <b>MiscellaneousChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>) <p> Constructor </p> <dl> <dt><i>source</i> (list of str)</dt> <dd> source code to be checked </dd> <dt><i>filename</i> (str)</dt> <dd> name of the source file </dd> <dt><i>tree</i> (ast.Module)</dt> <dd> AST tree of the source code </dd> <dt><i>select</i> (list of str)</dt> <dd> list of selected codes </dd> <dt><i>ignore</i> (list of str)</dt> <dd> list of codes to be ignored </dd> <dt><i>expected</i> (list of str)</dt> <dd> list of expected codes </dd> <dt><i>repeat</i> (bool)</dt> <dd> flag indicating to report each occurrence of a code </dd> <dt><i>args</i> (dict)</dt> <dd> dictionary of arguments for the miscellaneous checks </dd> </dl> <a NAME="MiscellaneousChecker.__checkBugBear" ID="MiscellaneousChecker.__checkBugBear"></a> <h4>MiscellaneousChecker.__checkBugBear</h4> <b>__checkBugBear</b>(<i></i>) <p> Private method for bugbear checks. </p> <a NAME="MiscellaneousChecker.__checkBuiltins" ID="MiscellaneousChecker.__checkBuiltins"></a> <h4>MiscellaneousChecker.__checkBuiltins</h4> <b>__checkBuiltins</b>(<i></i>) <p> Private method to check, if built-ins are shadowed. </p> <a NAME="MiscellaneousChecker.__checkCoding" ID="MiscellaneousChecker.__checkCoding"></a> <h4>MiscellaneousChecker.__checkCoding</h4> <b>__checkCoding</b>(<i></i>) <p> Private method to check the presence of a coding line and valid encodings. </p> <a NAME="MiscellaneousChecker.__checkCommentedCode" ID="MiscellaneousChecker.__checkCommentedCode"></a> <h4>MiscellaneousChecker.__checkCommentedCode</h4> <b>__checkCommentedCode</b>(<i></i>) <p> Private method to check for commented code. </p> <a NAME="MiscellaneousChecker.__checkComprehensions" ID="MiscellaneousChecker.__checkComprehensions"></a> <h4>MiscellaneousChecker.__checkComprehensions</h4> <b>__checkComprehensions</b>(<i></i>) <p> Private method to check some comprehension related things. </p> <p> This method is adapted from: flake8-comprehensions v3.16.0 Original: Copyright (c) 2017 Adam Johnson </p> <a NAME="MiscellaneousChecker.__checkCopyright" ID="MiscellaneousChecker.__checkCopyright"></a> <h4>MiscellaneousChecker.__checkCopyright</h4> <b>__checkCopyright</b>(<i></i>) <p> Private method to check the presence of a copyright statement. </p> <a NAME="MiscellaneousChecker.__checkDateTime" ID="MiscellaneousChecker.__checkDateTime"></a> <h4>MiscellaneousChecker.__checkDateTime</h4> <b>__checkDateTime</b>(<i></i>) <p> Private method to check use of naive datetime functions. </p> <a NAME="MiscellaneousChecker.__checkDefaultMatchCase" ID="MiscellaneousChecker.__checkDefaultMatchCase"></a> <h4>MiscellaneousChecker.__checkDefaultMatchCase</h4> <b>__checkDefaultMatchCase</b>(<i></i>) <p> Private method to check the default match case. </p> <a NAME="MiscellaneousChecker.__checkDictWithSortedKeys" ID="MiscellaneousChecker.__checkDictWithSortedKeys"></a> <h4>MiscellaneousChecker.__checkDictWithSortedKeys</h4> <b>__checkDictWithSortedKeys</b>(<i></i>) <p> Private method to check, if dictionary keys appear in sorted order. </p> <a NAME="MiscellaneousChecker.__checkExplicitStringConcat" ID="MiscellaneousChecker.__checkExplicitStringConcat"></a> <h4>MiscellaneousChecker.__checkExplicitStringConcat</h4> <b>__checkExplicitStringConcat</b>(<i></i>) <p> Private method to check for explicitly concatenated strings. </p> <a NAME="MiscellaneousChecker.__checkFormatString" ID="MiscellaneousChecker.__checkFormatString"></a> <h4>MiscellaneousChecker.__checkFormatString</h4> <b>__checkFormatString</b>(<i></i>) <p> Private method to check string format strings. </p> <a NAME="MiscellaneousChecker.__checkFuture" ID="MiscellaneousChecker.__checkFuture"></a> <h4>MiscellaneousChecker.__checkFuture</h4> <b>__checkFuture</b>(<i></i>) <p> Private method to check the __future__ imports. </p> <a NAME="MiscellaneousChecker.__checkGettext" ID="MiscellaneousChecker.__checkGettext"></a> <h4>MiscellaneousChecker.__checkGettext</h4> <b>__checkGettext</b>(<i></i>) <p> Private method to check the 'gettext' import statement. </p> <a NAME="MiscellaneousChecker.__checkImplicitStringConcat" ID="MiscellaneousChecker.__checkImplicitStringConcat"></a> <h4>MiscellaneousChecker.__checkImplicitStringConcat</h4> <b>__checkImplicitStringConcat</b>(<i></i>) <p> Private method to check for implicitly concatenated strings. </p> <a NAME="MiscellaneousChecker.__checkLineContinuation" ID="MiscellaneousChecker.__checkLineContinuation"></a> <h4>MiscellaneousChecker.__checkLineContinuation</h4> <b>__checkLineContinuation</b>(<i></i>) <p> Private method to check line continuation using backslash. </p> <a NAME="MiscellaneousChecker.__checkPep3101" ID="MiscellaneousChecker.__checkPep3101"></a> <h4>MiscellaneousChecker.__checkPep3101</h4> <b>__checkPep3101</b>(<i></i>) <p> Private method to check for old style string formatting. </p> <a NAME="MiscellaneousChecker.__checkPrintStatements" ID="MiscellaneousChecker.__checkPrintStatements"></a> <h4>MiscellaneousChecker.__checkPrintStatements</h4> <b>__checkPrintStatements</b>(<i></i>) <p> Private method to check for print statements. </p> <a NAME="MiscellaneousChecker.__checkProperties" ID="MiscellaneousChecker.__checkProperties"></a> <h4>MiscellaneousChecker.__checkProperties</h4> <b>__checkProperties</b>(<i></i>) <p> Private method to check for issue with property related methods. </p> <a NAME="MiscellaneousChecker.__checkReturn" ID="MiscellaneousChecker.__checkReturn"></a> <h4>MiscellaneousChecker.__checkReturn</h4> <b>__checkReturn</b>(<i></i>) <p> Private method to check return statements. </p> <a NAME="MiscellaneousChecker.__checkSysVersion" ID="MiscellaneousChecker.__checkSysVersion"></a> <h4>MiscellaneousChecker.__checkSysVersion</h4> <b>__checkSysVersion</b>(<i></i>) <p> Private method to check the use of sys.version and sys.version_info. </p> <a NAME="MiscellaneousChecker.__checkTuple" ID="MiscellaneousChecker.__checkTuple"></a> <h4>MiscellaneousChecker.__checkTuple</h4> <b>__checkTuple</b>(<i></i>) <p> Private method to check for one element tuples. </p> <a NAME="MiscellaneousChecker.__dictShouldBeChecked" ID="MiscellaneousChecker.__dictShouldBeChecked"></a> <h4>MiscellaneousChecker.__dictShouldBeChecked</h4> <b>__dictShouldBeChecked</b>(<i>node</i>) <p> Private function to test, if the node should be checked. </p> <dl> <dt><i>node</i> (ast.Dict)</dt> <dd> reference to the AST node </dd> </dl> <dl> <dt>Return:</dt> <dd> flag indicating to check the node </dd> </dl> <dl> <dt>Return Type:</dt> <dd> bool </dd> </dl> <a NAME="MiscellaneousChecker.__getCoding" ID="MiscellaneousChecker.__getCoding"></a> <h4>MiscellaneousChecker.__getCoding</h4> <b>__getCoding</b>(<i></i>) <p> Private method to get the defined coding of the source. </p> <dl> <dt>Return:</dt> <dd> tuple containing the line number and the coding </dd> </dl> <dl> <dt>Return Type:</dt> <dd> tuple of int and str </dd> </dl> <a NAME="MiscellaneousChecker.__getFields" ID="MiscellaneousChecker.__getFields"></a> <h4>MiscellaneousChecker.__getFields</h4> <b>__getFields</b>(<i>string</i>) <p> Private method to extract the format field information. </p> <dl> <dt><i>string</i> (str)</dt> <dd> format string to be parsed </dd> </dl> <dl> <dt>Return:</dt> <dd> format field information as a tuple with fields, implicit field definitions present and explicit field definitions present </dd> </dl> <dl> <dt>Return Type:</dt> <dd> tuple of set of str, bool, bool </dd> </dl> <a NAME="MiscellaneousChecker.__isImplicitStringConcat" ID="MiscellaneousChecker.__isImplicitStringConcat"></a> <h4>MiscellaneousChecker.__isImplicitStringConcat</h4> <b>__isImplicitStringConcat</b>(<i>first, second</i>) <p> Private method to check, if the given strings indicate an implicit string concatenation. </p> <dl> <dt><i>first</i> (tuple)</dt> <dd> first token </dd> <dt><i>second</i> (tuple)</dt> <dd> second token </dd> </dl> <dl> <dt>Return:</dt> <dd> flag indicating an implicit string concatenation </dd> </dl> <dl> <dt>Return Type:</dt> <dd> bool </dd> </dl> <div align="right"><a href="#top">Up</a></div> <hr /> <hr /> <a NAME="pairwise" ID="pairwise"></a> <h2>pairwise</h2> <b>pairwise</b>(<i>iterable</i>) <div align="right"><a href="#top">Up</a></div> <hr /> </body></html>