|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric6.Plugins.CheckerPlugins.CodeStyleChecker.AnnotationsChecker</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>eric6.Plugins.CheckerPlugins.CodeStyleChecker.AnnotationsChecker</h1> |
|
23 <p> |
|
24 Module implementing a checker for function type annotations. |
|
25 </p> |
|
26 <h3>Global Attributes</h3> |
|
27 <table> |
|
28 <tr><td>None</td></tr> |
|
29 </table> |
|
30 <h3>Classes</h3> |
|
31 <table> |
|
32 <tr> |
|
33 <td><a href="#AnnotationsChecker">AnnotationsChecker</a></td> |
|
34 <td>Class implementing a checker for function type annotations.</td> |
|
35 </tr><tr> |
|
36 <td><a href="#FunctionVisitor">FunctionVisitor</a></td> |
|
37 <td>Class implementing a node visitor to check function annotations.</td> |
|
38 </tr> |
|
39 </table> |
|
40 <h3>Functions</h3> |
|
41 <table> |
|
42 <tr><td>None</td></tr> |
|
43 </table> |
|
44 <hr /><hr /> |
|
45 <a NAME="AnnotationsChecker" ID="AnnotationsChecker"></a> |
|
46 <h2>AnnotationsChecker</h2> |
|
47 <p> |
|
48 Class implementing a checker for function type annotations. |
|
49 </p> |
|
50 <h3>Derived from</h3> |
|
51 object |
|
52 <h3>Class Attributes</h3> |
|
53 <table> |
|
54 <tr><td>Codes</td></tr> |
|
55 </table> |
|
56 <h3>Class Methods</h3> |
|
57 <table> |
|
58 <tr><td>None</td></tr> |
|
59 </table> |
|
60 <h3>Methods</h3> |
|
61 <table> |
|
62 <tr> |
|
63 <td><a href="#AnnotationsChecker.__init__">AnnotationsChecker</a></td> |
|
64 <td>Constructor</td> |
|
65 </tr><tr> |
|
66 <td><a href="#AnnotationsChecker.__checkFunctionAnnotations">__checkFunctionAnnotations</a></td> |
|
67 <td>Private method to check for function annotation issues.</td> |
|
68 </tr><tr> |
|
69 <td><a href="#AnnotationsChecker.__error">__error</a></td> |
|
70 <td>Private method to record an issue.</td> |
|
71 </tr><tr> |
|
72 <td><a href="#AnnotationsChecker.__generateTree">__generateTree</a></td> |
|
73 <td>Private method to generate an AST for our source.</td> |
|
74 </tr><tr> |
|
75 <td><a href="#AnnotationsChecker.__ignoreCode">__ignoreCode</a></td> |
|
76 <td>Private method to check if the message code should be ignored.</td> |
|
77 </tr><tr> |
|
78 <td><a href="#AnnotationsChecker.__reportInvalidSyntax">__reportInvalidSyntax</a></td> |
|
79 <td>Private method to report a syntax error.</td> |
|
80 </tr><tr> |
|
81 <td><a href="#AnnotationsChecker.run">run</a></td> |
|
82 <td>Public method to check the given source against annotation issues.</td> |
|
83 </tr> |
|
84 </table> |
|
85 <h3>Static Methods</h3> |
|
86 <table> |
|
87 <tr><td>None</td></tr> |
|
88 </table> |
|
89 <a NAME="AnnotationsChecker.__init__" ID="AnnotationsChecker.__init__"></a> |
|
90 <h4>AnnotationsChecker (Constructor)</h4> |
|
91 <b>AnnotationsChecker</b>(<i>source, filename, select, ignore, expected, repeat</i>) |
|
92 <p> |
|
93 Constructor |
|
94 </p><dl> |
|
95 <dt><i>source</i> (list of str)</dt> |
|
96 <dd> |
|
97 source code to be checked |
|
98 </dd><dt><i>filename</i> (str)</dt> |
|
99 <dd> |
|
100 name of the source file |
|
101 </dd><dt><i>select</i> (list of str)</dt> |
|
102 <dd> |
|
103 list of selected codes |
|
104 </dd><dt><i>ignore</i> (list of str)</dt> |
|
105 <dd> |
|
106 list of codes to be ignored |
|
107 </dd><dt><i>expected</i> (list of str)</dt> |
|
108 <dd> |
|
109 list of expected codes |
|
110 </dd><dt><i>repeat</i> (bool)</dt> |
|
111 <dd> |
|
112 flag indicating to report each occurrence of a code |
|
113 </dd> |
|
114 </dl><a NAME="AnnotationsChecker.__checkFunctionAnnotations" ID="AnnotationsChecker.__checkFunctionAnnotations"></a> |
|
115 <h4>AnnotationsChecker.__checkFunctionAnnotations</h4> |
|
116 <b>__checkFunctionAnnotations</b>(<i></i>) |
|
117 <p> |
|
118 Private method to check for function annotation issues. |
|
119 </p><a NAME="AnnotationsChecker.__error" ID="AnnotationsChecker.__error"></a> |
|
120 <h4>AnnotationsChecker.__error</h4> |
|
121 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
122 <p> |
|
123 Private method to record an issue. |
|
124 </p><dl> |
|
125 <dt><i>lineNumber</i> (int)</dt> |
|
126 <dd> |
|
127 line number of the issue |
|
128 </dd><dt><i>offset</i> (int)</dt> |
|
129 <dd> |
|
130 position within line of the issue |
|
131 </dd><dt><i>code</i> (str)</dt> |
|
132 <dd> |
|
133 message code |
|
134 </dd><dt><i>args</i> (list)</dt> |
|
135 <dd> |
|
136 arguments for the message |
|
137 </dd> |
|
138 </dl><a NAME="AnnotationsChecker.__generateTree" ID="AnnotationsChecker.__generateTree"></a> |
|
139 <h4>AnnotationsChecker.__generateTree</h4> |
|
140 <b>__generateTree</b>(<i></i>) |
|
141 <p> |
|
142 Private method to generate an AST for our source. |
|
143 </p><dl> |
|
144 <dt>Returns:</dt> |
|
145 <dd> |
|
146 generated AST |
|
147 </dd> |
|
148 </dl><dl> |
|
149 <dt>Return Type:</dt> |
|
150 <dd> |
|
151 ast.Module |
|
152 </dd> |
|
153 </dl><a NAME="AnnotationsChecker.__ignoreCode" ID="AnnotationsChecker.__ignoreCode"></a> |
|
154 <h4>AnnotationsChecker.__ignoreCode</h4> |
|
155 <b>__ignoreCode</b>(<i>code</i>) |
|
156 <p> |
|
157 Private method to check if the message code should be ignored. |
|
158 </p><dl> |
|
159 <dt><i>code</i> (str)</dt> |
|
160 <dd> |
|
161 message code to check for |
|
162 </dd> |
|
163 </dl><dl> |
|
164 <dt>Returns:</dt> |
|
165 <dd> |
|
166 flag indicating to ignore the given code |
|
167 </dd> |
|
168 </dl><dl> |
|
169 <dt>Return Type:</dt> |
|
170 <dd> |
|
171 bool |
|
172 </dd> |
|
173 </dl><a NAME="AnnotationsChecker.__reportInvalidSyntax" ID="AnnotationsChecker.__reportInvalidSyntax"></a> |
|
174 <h4>AnnotationsChecker.__reportInvalidSyntax</h4> |
|
175 <b>__reportInvalidSyntax</b>(<i></i>) |
|
176 <p> |
|
177 Private method to report a syntax error. |
|
178 </p><a NAME="AnnotationsChecker.run" ID="AnnotationsChecker.run"></a> |
|
179 <h4>AnnotationsChecker.run</h4> |
|
180 <b>run</b>(<i></i>) |
|
181 <p> |
|
182 Public method to check the given source against annotation issues. |
|
183 </p> |
|
184 <div align="right"><a href="#top">Up</a></div> |
|
185 <hr /><hr /> |
|
186 <a NAME="FunctionVisitor" ID="FunctionVisitor"></a> |
|
187 <h2>FunctionVisitor</h2> |
|
188 <p> |
|
189 Class implementing a node visitor to check function annotations. |
|
190 </p><p> |
|
191 Note: this class is modelled after flake8-annotations checker. |
|
192 </p> |
|
193 <h3>Derived from</h3> |
|
194 ast.NodeVisitor |
|
195 <h3>Class Attributes</h3> |
|
196 <table> |
|
197 <tr><td>None</td></tr> |
|
198 </table> |
|
199 <h3>Class Methods</h3> |
|
200 <table> |
|
201 <tr><td>None</td></tr> |
|
202 </table> |
|
203 <h3>Methods</h3> |
|
204 <table> |
|
205 <tr> |
|
206 <td><a href="#FunctionVisitor.__init__">FunctionVisitor</a></td> |
|
207 <td>Constructor</td> |
|
208 </tr><tr> |
|
209 <td><a href="#FunctionVisitor.__checkFunctionNode">__checkFunctionNode</a></td> |
|
210 <td>Private method to check an individual function definition node.</td> |
|
211 </tr><tr> |
|
212 <td><a href="#FunctionVisitor.__classifyArgumentError">__classifyArgumentError</a></td> |
|
213 <td>Private method to classify and record an argument annotation issue.</td> |
|
214 </tr><tr> |
|
215 <td><a href="#FunctionVisitor.__classifyReturnError">__classifyReturnError</a></td> |
|
216 <td>Private method to classify and record a return annotation issue.</td> |
|
217 </tr><tr> |
|
218 <td><a href="#FunctionVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> |
|
219 <td>Public method to handle an async function or method definition.</td> |
|
220 </tr><tr> |
|
221 <td><a href="#FunctionVisitor.visit_ClassDef">visit_ClassDef</a></td> |
|
222 <td>Public method to handle class definitions.</td> |
|
223 </tr><tr> |
|
224 <td><a href="#FunctionVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
225 <td>Public method to handle a function or method definition.</td> |
|
226 </tr> |
|
227 </table> |
|
228 <h3>Static Methods</h3> |
|
229 <table> |
|
230 <tr><td>None</td></tr> |
|
231 </table> |
|
232 <a NAME="FunctionVisitor.__init__" ID="FunctionVisitor.__init__"></a> |
|
233 <h4>FunctionVisitor (Constructor)</h4> |
|
234 <b>FunctionVisitor</b>(<i>sourceLines</i>) |
|
235 <p> |
|
236 Constructor |
|
237 </p><dl> |
|
238 <dt><i>sourceLines</i> (list of str)</dt> |
|
239 <dd> |
|
240 lines of source code |
|
241 </dd> |
|
242 </dl><a NAME="FunctionVisitor.__checkFunctionNode" ID="FunctionVisitor.__checkFunctionNode"></a> |
|
243 <h4>FunctionVisitor.__checkFunctionNode</h4> |
|
244 <b>__checkFunctionNode</b>(<i>node, classMethod=False</i>) |
|
245 <p> |
|
246 Private method to check an individual function definition node. |
|
247 </p><dl> |
|
248 <dt><i>node</i> (ast.FunctionDef or ast.AsyncFunctionDef)</dt> |
|
249 <dd> |
|
250 reference to the node to be processed |
|
251 </dd><dt><i>classMethod</i> (bool)</dt> |
|
252 <dd> |
|
253 flag indicating a class method |
|
254 </dd> |
|
255 </dl><a NAME="FunctionVisitor.__classifyArgumentError" ID="FunctionVisitor.__classifyArgumentError"></a> |
|
256 <h4>FunctionVisitor.__classifyArgumentError</h4> |
|
257 <b>__classifyArgumentError</b>(<i>argNode, argType, methodType</i>) |
|
258 <p> |
|
259 Private method to classify and record an argument annotation issue. |
|
260 </p><dl> |
|
261 <dt><i>argNode</i> (ast.arguments)</dt> |
|
262 <dd> |
|
263 reference to the argument node |
|
264 </dd><dt><i>argType</i> (str)</dt> |
|
265 <dd> |
|
266 type of the argument node |
|
267 </dd><dt><i>methodType</i> (str)</dt> |
|
268 <dd> |
|
269 type of method/function the argument belongs to |
|
270 </dd> |
|
271 </dl><a NAME="FunctionVisitor.__classifyReturnError" ID="FunctionVisitor.__classifyReturnError"></a> |
|
272 <h4>FunctionVisitor.__classifyReturnError</h4> |
|
273 <b>__classifyReturnError</b>(<i>methodType, visibilityType, lineno, colOffset</i>) |
|
274 <p> |
|
275 Private method to classify and record a return annotation issue. |
|
276 </p><dl> |
|
277 <dt><i>methodType</i> (str)</dt> |
|
278 <dd> |
|
279 type of method/function the argument belongs to |
|
280 </dd><dt><i>visibilityType</i> (str)</dt> |
|
281 <dd> |
|
282 visibility of the function |
|
283 </dd><dt><i>lineno</i> (int)</dt> |
|
284 <dd> |
|
285 line number |
|
286 </dd><dt><i>colOffset</i> (int)</dt> |
|
287 <dd> |
|
288 column number |
|
289 </dd> |
|
290 </dl><a NAME="FunctionVisitor.visit_AsyncFunctionDef" ID="FunctionVisitor.visit_AsyncFunctionDef"></a> |
|
291 <h4>FunctionVisitor.visit_AsyncFunctionDef</h4> |
|
292 <b>visit_AsyncFunctionDef</b>(<i>node</i>) |
|
293 <p> |
|
294 Public method to handle an async function or method definition. |
|
295 </p><dl> |
|
296 <dt><i>node</i> (ast.AsyncFunctionDef)</dt> |
|
297 <dd> |
|
298 reference to the node to be processed |
|
299 </dd> |
|
300 </dl><a NAME="FunctionVisitor.visit_ClassDef" ID="FunctionVisitor.visit_ClassDef"></a> |
|
301 <h4>FunctionVisitor.visit_ClassDef</h4> |
|
302 <b>visit_ClassDef</b>(<i>node</i>) |
|
303 <p> |
|
304 Public method to handle class definitions. |
|
305 </p><dl> |
|
306 <dt><i>node</i> (ast.ClassDef)</dt> |
|
307 <dd> |
|
308 reference to the node to be processed |
|
309 </dd> |
|
310 </dl><a NAME="FunctionVisitor.visit_FunctionDef" ID="FunctionVisitor.visit_FunctionDef"></a> |
|
311 <h4>FunctionVisitor.visit_FunctionDef</h4> |
|
312 <b>visit_FunctionDef</b>(<i>node</i>) |
|
313 <p> |
|
314 Public method to handle a function or method definition. |
|
315 </p><dl> |
|
316 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
317 <dd> |
|
318 reference to the node to be processed |
|
319 </dd> |
|
320 </dl> |
|
321 <div align="right"><a href="#top">Up</a></div> |
|
322 <hr /> |
|
323 </body></html> |