235 kwOnly = [arg.arg for arg in node.args.kwonlyargs] |
235 kwOnly = [arg.arg for arg in node.args.kwonlyargs] |
236 return posArgs + kwOnly |
236 return posArgs + kwOnly |
237 |
237 |
238 def __error(self, node, code): |
238 def __error(self, node, code): |
239 """ |
239 """ |
240 Private method to build the error information |
240 Private method to build the error information. |
241 |
241 |
242 @param node AST node to report an error for |
242 @param node AST node to report an error for |
243 @param code error code to report (string) |
243 @param code error code to report (string) |
244 @return tuple giving line number, offset within line and error code |
244 @return tuple giving line number, offset within line and error code |
245 (integer, integer, string) |
245 (integer, integer, string) |
270 def __checkNameToBeAvoided(self, node, parents): |
270 def __checkNameToBeAvoided(self, node, parents): |
271 """ |
271 """ |
272 Private class to check the given node for a name to be avoided (N831). |
272 Private class to check the given node for a name to be avoided (N831). |
273 |
273 |
274 @param node AST note to check |
274 @param node AST note to check |
|
275 @param parents list of parent nodes |
275 @return tuple giving line number, offset within line and error code |
276 @return tuple giving line number, offset within line and error code |
276 (integer, integer, string) |
277 (integer, integer, string) |
277 """ |
278 """ |
278 if isinstance(node, (ast.ClassDef, ast.FunctionDef)): |
279 if isinstance(node, (ast.ClassDef, ast.FunctionDef)): |
279 name = node.name |
280 name = node.name |
305 |
306 |
306 Almost without exception, class names use the CapWords convention. |
307 Almost without exception, class names use the CapWords convention. |
307 Classes for internal use have a leading underscore in addition. |
308 Classes for internal use have a leading underscore in addition. |
308 |
309 |
309 @param node AST note to check |
310 @param node AST note to check |
|
311 @param parents list of parent nodes |
310 @return tuple giving line number, offset within line and error code |
312 @return tuple giving line number, offset within line and error code |
311 (integer, integer, string) |
313 (integer, integer, string) |
312 """ |
314 """ |
313 if not self.CamelcaseRegexp.match(node.name): |
315 if not self.CamelcaseRegexp.match(node.name): |
314 yield self.__error(node, "N801") |
316 yield self.__error(node, "N801") |
323 methods '__' in front and back are not allowed. Mixed case is allowed |
325 methods '__' in front and back are not allowed. Mixed case is allowed |
324 only in contexts where that's already the prevailing style |
326 only in contexts where that's already the prevailing style |
325 (e.g. threading.py), to retain backwards compatibility. |
327 (e.g. threading.py), to retain backwards compatibility. |
326 |
328 |
327 @param node AST note to check |
329 @param node AST note to check |
|
330 @param parents list of parent nodes |
328 @return tuple giving line number, offset within line and error code |
331 @return tuple giving line number, offset within line and error code |
329 (integer, integer, string) |
332 (integer, integer, string) |
330 """ |
333 """ |
331 functionType = getattr(node, "function_type", "function") |
334 functionType = getattr(node, "function_type", "function") |
332 name = node.name |
335 name = node.name |
342 The argument names of a function should be lowercase, with words |
345 The argument names of a function should be lowercase, with words |
343 separated by underscores. A class method should have 'cls' as the |
346 separated by underscores. A class method should have 'cls' as the |
344 first argument. A method should have 'self' as the first argument. |
347 first argument. A method should have 'self' as the first argument. |
345 |
348 |
346 @param node AST note to check |
349 @param node AST note to check |
|
350 @param parents list of parent nodes |
347 @return tuple giving line number, offset within line and error code |
351 @return tuple giving line number, offset within line and error code |
348 (integer, integer, string) |
352 (integer, integer, string) |
349 """ |
353 """ |
350 if node.args.kwarg is not None: |
354 if node.args.kwarg is not None: |
351 if not self.LowercaseRegex.match(node.args.kwarg): |
355 if not self.LowercaseRegex.match(node.args.kwarg): |
386 Private method to check local variables in functions (N821). |
390 Private method to check local variables in functions (N821). |
387 |
391 |
388 Local variables in functions should be lowercase. |
392 Local variables in functions should be lowercase. |
389 |
393 |
390 @param node AST note to check |
394 @param node AST note to check |
|
395 @param parents list of parent nodes |
391 @return tuple giving line number, offset within line and error code |
396 @return tuple giving line number, offset within line and error code |
392 (integer, integer, string) |
397 (integer, integer, string) |
393 """ |
398 """ |
394 for parentFunc in reversed(parents): |
399 for parentFunc in reversed(parents): |
395 if isinstance(parentFunc, ast.ClassDef): |
400 if isinstance(parentFunc, ast.ClassDef): |
411 Private method to check module naming conventions (N807, N808). |
416 Private method to check module naming conventions (N807, N808). |
412 |
417 |
413 Module and package names should be lowercase. |
418 Module and package names should be lowercase. |
414 |
419 |
415 @param node AST note to check |
420 @param node AST note to check |
|
421 @param parents list of parent nodes |
416 @return tuple giving line number, offset within line and error code |
422 @return tuple giving line number, offset within line and error code |
417 (integer, integer, string) |
423 (integer, integer, string) |
418 """ |
424 """ |
419 if self.__filename: |
425 if self.__filename: |
420 moduleName = os.path.splitext(os.path.basename(self.__filename))[0] |
426 moduleName = os.path.splitext(os.path.basename(self.__filename))[0] |
432 """ |
438 """ |
433 Private method to check that imports don't change the |
439 Private method to check that imports don't change the |
434 naming convention (N811, N812, N813, N814). |
440 naming convention (N811, N812, N813, N814). |
435 |
441 |
436 @param node AST note to check |
442 @param node AST note to check |
|
443 @param parents list of parent nodes |
437 @return tuple giving line number, offset within line and error code |
444 @return tuple giving line number, offset within line and error code |
438 (integer, integer, string) |
445 (integer, integer, string) |
439 """ |
446 """ |
440 for name in node.names: |
447 for name in node.names: |
441 if not name.asname: |
448 if not name.asname: |