198 |
198 |
199 return unpackArgs(node.args.args) |
199 return unpackArgs(node.args.args) |
200 |
200 |
201 def __error(self, node, code): |
201 def __error(self, node, code): |
202 """ |
202 """ |
203 Private method to build the error information |
203 Private method to build the error information. |
204 |
204 |
205 @param node AST node to report an error for |
205 @param node AST node to report an error for |
206 @param code error code to report (string) |
206 @param code error code to report (string) |
207 @return tuple giving line number, offset within line and error code |
207 @return tuple giving line number, offset within line and error code |
208 (integer, integer, string) |
208 (integer, integer, string) |
233 def __checkNameToBeAvoided(self, node, parents): |
233 def __checkNameToBeAvoided(self, node, parents): |
234 """ |
234 """ |
235 Private class to check the given node for a name to be avoided (N831). |
235 Private class to check the given node for a name to be avoided (N831). |
236 |
236 |
237 @param node AST note to check |
237 @param node AST note to check |
|
238 @param parents list of parent nodes |
238 @return tuple giving line number, offset within line and error code |
239 @return tuple giving line number, offset within line and error code |
239 (integer, integer, string) |
240 (integer, integer, string) |
240 """ |
241 """ |
241 if isinstance(node, (ast.ClassDef, ast.FunctionDef)): |
242 if isinstance(node, (ast.ClassDef, ast.FunctionDef)): |
242 name = node.name |
243 name = node.name |
268 |
269 |
269 Almost without exception, class names use the CapWords convention. |
270 Almost without exception, class names use the CapWords convention. |
270 Classes for internal use have a leading underscore in addition. |
271 Classes for internal use have a leading underscore in addition. |
271 |
272 |
272 @param node AST note to check |
273 @param node AST note to check |
|
274 @param parents list of parent nodes |
273 @return tuple giving line number, offset within line and error code |
275 @return tuple giving line number, offset within line and error code |
274 (integer, integer, string) |
276 (integer, integer, string) |
275 """ |
277 """ |
276 if not self.CamelcaseRegexp.match(node.name): |
278 if not self.CamelcaseRegexp.match(node.name): |
277 yield self.__error(node, "N801") |
279 yield self.__error(node, "N801") |
286 methods '__' in front and back are not allowed. Mixed case is allowed |
288 methods '__' in front and back are not allowed. Mixed case is allowed |
287 only in contexts where that's already the prevailing style |
289 only in contexts where that's already the prevailing style |
288 (e.g. threading.py), to retain backwards compatibility. |
290 (e.g. threading.py), to retain backwards compatibility. |
289 |
291 |
290 @param node AST note to check |
292 @param node AST note to check |
|
293 @param parents list of parent nodes |
291 @return tuple giving line number, offset within line and error code |
294 @return tuple giving line number, offset within line and error code |
292 (integer, integer, string) |
295 (integer, integer, string) |
293 """ |
296 """ |
294 functionType = getattr(node, "function_type", "function") |
297 functionType = getattr(node, "function_type", "function") |
295 name = node.name |
298 name = node.name |
305 The argument names of a function should be lowercase, with words |
308 The argument names of a function should be lowercase, with words |
306 separated by underscores. A class method should have 'cls' as the |
309 separated by underscores. A class method should have 'cls' as the |
307 first argument. A method should have 'self' as the first argument. |
310 first argument. A method should have 'self' as the first argument. |
308 |
311 |
309 @param node AST note to check |
312 @param node AST note to check |
|
313 @param parents list of parent nodes |
310 @return tuple giving line number, offset within line and error code |
314 @return tuple giving line number, offset within line and error code |
311 (integer, integer, string) |
315 (integer, integer, string) |
312 """ |
316 """ |
313 if node.args.kwarg is not None: |
317 if node.args.kwarg is not None: |
314 if not self.LowercaseRegex.match(node.args.kwarg): |
318 if not self.LowercaseRegex.match(node.args.kwarg): |
349 Private method to check local variables in functions (N821). |
353 Private method to check local variables in functions (N821). |
350 |
354 |
351 Local variables in functions should be lowercase. |
355 Local variables in functions should be lowercase. |
352 |
356 |
353 @param node AST note to check |
357 @param node AST note to check |
|
358 @param parents list of parent nodes |
354 @return tuple giving line number, offset within line and error code |
359 @return tuple giving line number, offset within line and error code |
355 (integer, integer, string) |
360 (integer, integer, string) |
356 """ |
361 """ |
357 for parentFunc in reversed(parents): |
362 for parentFunc in reversed(parents): |
358 if isinstance(parentFunc, ast.ClassDef): |
363 if isinstance(parentFunc, ast.ClassDef): |
374 Private method to check module naming conventions (N807, N808). |
379 Private method to check module naming conventions (N807, N808). |
375 |
380 |
376 Module and package names should be lowercase. |
381 Module and package names should be lowercase. |
377 |
382 |
378 @param node AST note to check |
383 @param node AST note to check |
|
384 @param parents list of parent nodes |
379 @return tuple giving line number, offset within line and error code |
385 @return tuple giving line number, offset within line and error code |
380 (integer, integer, string) |
386 (integer, integer, string) |
381 """ |
387 """ |
382 if self.__filename: |
388 if self.__filename: |
383 moduleName = os.path.splitext(os.path.basename(self.__filename))[0] |
389 moduleName = os.path.splitext(os.path.basename(self.__filename))[0] |
395 """ |
401 """ |
396 Private method to check that imports don't change the |
402 Private method to check that imports don't change the |
397 naming convention (N811, N812, N813, N814). |
403 naming convention (N811, N812, N813, N814). |
398 |
404 |
399 @param node AST note to check |
405 @param node AST note to check |
|
406 @param parents list of parent nodes |
400 @return tuple giving line number, offset within line and error code |
407 @return tuple giving line number, offset within line and error code |
401 (integer, integer, string) |
408 (integer, integer, string) |
402 """ |
409 """ |
403 for name in node.names: |
410 for name in node.names: |
404 if not name.asname: |
411 if not name.asname: |