Plugins/CheckerPlugins/Pep8/Pep8NamingChecker.py

Sun, 08 Sep 2013 13:16:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 08 Sep 2013 13:16:07 +0200
changeset 2894
8e4264045fc9
child 2895
4a44d92757f9
permissions
-rw-r--r--

Started implementing a PEP-8 naming checker.

2894
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de>
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a checker for PEP-8 naming conventions.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import collections
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import ast
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import re
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import os
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt4.QtCore import QT_TRANSLATE_NOOP, QCoreApplication
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 # TODO: port this to Py2
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class Pep8NamingChecker(object):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing a checker for PEP-8 naming conventions.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 LowercaseRegex = re.compile(r"[_a-z][_a-z0-9]*$")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 UppercaseRegexp = re.compile(r"[_A-Z][_A-Z0-9]*$")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 CamelcaseRegexp = re.compile(r"_?[A-Z][a-zA-Z0-9]*$")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 MixedcaseRegexp = re.compile(r"_?[a-z][a-zA-Z0-9]*$")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Codes = [
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 "N801", "N802", "N803", "N804", "N805", "N806", "N807", "N808",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 "N811", "N812", "N813", "N814", "N821", "N831"
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 ]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Messages = {
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 "N801": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 "class names should use CapWords convention"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 "N802": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 "function name should be lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 "N803": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 "argument name should be lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 "N804": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 "first argument of a class method should be named 'cls'"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 "N805": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 "first argument of a method should be named 'self'"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 "N806": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 "first argument of a static method should not be named"
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 " 'self' or 'cls"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 "N807": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 "module names should be lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 "N808": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 "package names should be lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 "N811": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 "constant imported as non constant"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 "N812": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 "lowercase imported as non lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 "N813": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 "camelcase imported as lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 "N814": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 "camelcase imported as constant"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 "N821": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 "variable in function should be lowercase"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 "N831": QT_TRANSLATE_NOOP("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 "names 'l', 'O' and 'I' should be avoided"),
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 }
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def __init__(self, tree, filename):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Constructor (according to pep8.py API)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @param tree AST tree of the source file
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param filename name of the source file (string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__parents = collections.deque()
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__tree = tree
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__filename = filename
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__checkers = {
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 "classdef": [self.__checkClassName],
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 "functiondef": [self.__checkFuntionName,
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.__checkFunctionArgumentNames,
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 ],
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 "assign": [self.__checkVariablesInFunction],
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 "importfrom": [self.__checkImportAs],
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 "module": [self.__checkModule],
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 }
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 def run(self):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 Public method run by the pep8.py checker.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 @return tuple giving line number, offset within line, code and
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 checker function
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 if self.__tree:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 return self.__visitTree(self.__tree)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 else:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 return ()
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @classmethod
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 def getMessage(cls, code, *args):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 Class method to get a translated and formatted message for a
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 given code.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @param code message code (string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @param args arguments for a formatted message (list)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @return translated and formatted message (string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 if code in cls.Messages:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 return code + " " + QCoreApplication.translate("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 cls.Messages[code]).format(*args)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 else:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 return code + " " + QCoreApplication.translate("Pep8NamingChecker",
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 "no message for this code defined")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def __visitTree(self, node):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Private method to scan the given AST tree.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @param node AST tree node to scan
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @return tuple giving line number, offset within line, code and
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 checker function
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 for error in self.__visitNode(node):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 yield error
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__parents.append(node)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 for child in ast.iter_child_nodes(node):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 for error in self.__visitTree(child):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 yield error
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.__parents.pop()
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 def __visitNode(self, node):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 Private method to inspect the given AST node.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @param node AST tree node to inspect
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @return tuple giving line number, offset within line, code and
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 checker function
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 if isinstance(node, ast.ClassDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.__tagClassFunctions(node)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 elif isinstance(node, ast.FunctionDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.__findGlobalDefs(node)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 checkerName = node.__class__.__name__.lower()
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 if checkerName in self.__checkers:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 for checker in self.__checkers[checkerName]:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 for error in checker(node, self.__parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 yield error + (self.__checkers[checkerName],)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 def __tagClassFunctions(self, classNode):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 Private method to tag functions if they are methods, class methods or
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 static methods.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @param classNode AST tree node to tag
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 # try to find all 'old style decorators' like
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 # m = staticmethod(m)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 lateDecoration = {}
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 for node in ast.iter_child_nodes(classNode):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 if not (isinstance(node, ast.Assign) and
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 isinstance(node.value, ast.Call) and
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 isinstance(node.value.func, ast.Name)):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 continue
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 funcName = node.value.func.id
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 if funcName in ("classmethod", "staticmethod"):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 meth = (len(node.value.args) == 1 and node.value.args[0])
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 if isinstance(meth, ast.Name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 lateDecoration[meth.id] = funcName
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 # iterate over all functions and tag them
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 for node in ast.iter_child_nodes(classNode):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 if not isinstance(node, ast.FunctionDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 continue
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 node.function_type = 'method'
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 if node.name == "__new__":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 node.function_type = "classmethod"
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 if node.name in lateDecoration:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 node.function_type = lateDecoration[node.name]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 elif node.decorator_list:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 names = [d.id for d in node.decorator_list
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 if isinstance(d, ast.Name) and
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 d.id in ("classmethod", "staticmethod")]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 if names:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 node.function_type = names[0]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 def __findGlobalDefs(self, functionNode):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 Private method amend a node with global definitions information.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 @param functionNode AST tree node to amend
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 globalNames = set()
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 nodesToCheck = collections.deque(ast.iter_child_nodes(functionNode))
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 while nodesToCheck:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 node = nodesToCheck.pop()
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 if isinstance(node, ast.Global):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 globalNames.update(node.names)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 if not isinstance(node, (ast.FunctionDef, ast.ClassDef)):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 nodesToCheck.extend(ast.iter_child_nodes(node))
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 functionNode.global_names = globalNames
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 def __getArgNames(self, node):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 Private method to get the argument names of a function node.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @param node AST node to extract arguments names from
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 @return list of argument names (list of string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 posArgs = [arg.arg for arg in node.args.args]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 kwOnly = [arg.arg for arg in node.args.kwonlyargs]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 return posArgs + kwOnly
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 def __error(self, node, code):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 Private method to build the error information
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 @param node AST node to report an error for
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 @param code error code to report (string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 if isinstance(node, ast.Module):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 lineno = 0
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 offset = 0
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 else:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 lineno = node.lineno
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 offset = node.col_offset
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 if isinstance(node, ast.ClassDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 lineno += len(node.decorator_list)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 offset += 6
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 elif isinstance(node, ast.FunctionDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 lineno += len(node.decorator_list)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 offset += 4
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 return (lineno, offset, code)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 def __isNameToBeAvoided(self, name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 Private method to check, if the given name should be avoided.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 @param name name to be checked (string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @return flag indicating to avoid it (boolen)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 return name in ("l", "O", "I")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 def __checkClassName(self, node, parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 Private class to check the given node for class name
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 conventions (N801, N831).
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 Almost without exception, class names use the CapWords convention.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 Classes for internal use have a leading underscore in addition.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 @param node AST note to check
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 if self.__isNameToBeAvoided(node.name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 yield self.__error(node, "N831")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 if not self.CamelcaseRegexp.match(node.name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 yield self.__error(node, "N801")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 def __checkFuntionName(self, node, parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 Private class to check the given node for function name
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 conventions (N802, N831).
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 Function names should be lowercase, with words separated by underscores
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 as necessary to improve readability. Functions <b>not</b> being
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 methods '__' in front and back are not allowed. Mixed case is allowed
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 only in contexts where that's already the prevailing style
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 (e.g. threading.py), to retain backwards compatibility.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 @param node AST note to check
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 functionType = getattr(node, "function_type", "function")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 name = node.name
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 if self.__isNameToBeAvoided(name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 yield self.__error(node, "N831")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 if (functionType == "function" and "__" in (name[:2], name[-2:])) or \
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 not self.LowercaseRegex.match(name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 yield self.__error(node, "N802")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 def __checkFunctionArgumentNames(self, node, parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 Private class to check the argument names of functions
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 (N803, N804, N805, N806, N831).
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 The argument names of a function should be lowercase, with words
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 separated by underscores. A class method should have 'cls' as the
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 first argument. A method should have 'self' as the first argument.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 @param node AST note to check
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 if node.args.kwarg is not None:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 if not self.LowercaseRegex.match(node.args.kwarg):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 yield self.__error(node, "N803")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 if node.args.vararg is not None:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 if not self.LowercaseRegex.match(node.args.vararg):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 yield self.__error(node, "N803")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 argNames = self.__getArgNames(node)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 if not argNames:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 functionType = getattr(node, "function_type", "function")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 if functionType == "method":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 if argNames[0] != "self":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 yield self.__error(node, "N805")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 elif functionType == "classmethod":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 if argNames[0] != "cls":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 yield self.__error(node, "N804")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 elif functionType == "staticmethod":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 if argNames[0] in ("cls", "self"):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 yield self.__error(node, "N806")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 for arg in argNames:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 if self.__isNameToBeAvoided(arg):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 yield self.__error(node, "N831")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 if not self.LowercaseRegex.match(arg):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 yield self.__error(node, "N803")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 def __checkVariablesInFunction(self, node, parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 Private method to check local variables in functions (N821, N831).
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 Local variables in functions should be lowercase.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 @param node AST note to check
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 for parentFunc in reversed(parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 if isinstance(parentFunc, ast.ClassDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 if isinstance(parentFunc, ast.FunctionDef):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 break
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 else:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 for target in node.targets:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 name = isinstance(target, ast.Name) and target.id
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 if not name or name in parentFunc.global_names:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 if self.__isNameToBeAvoided(name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 yield self.__error(node, "N831")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 return
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 if not self.LowercaseRegex.match(name) and name[:1] != '_':
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 yield self.__error(target, "N821")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 def __checkModule(self, node, parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 Private method to check module naming conventions (N807, N808).
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 Module and package names should be lowercase.
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 @param node AST note to check
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 if self.__filename:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 moduleName = os.path.splitext(os.path.basename(self.__filename))[0]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 if moduleName.lower() != moduleName:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 yield self.__error(node, "N807")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 if moduleName == "__init__":
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 # we got a package
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 packageName = \
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 os.path.split(os.path.dirname(self.__filename))[1]
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 if packageName.lower != packageName:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 yield self.__error(node, "N808")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 def __checkImportAs(self, node, parents):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 Private method to check that imports don't change the
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 naming convention (N811, N812, N813, N814).
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 @param node AST note to check
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 @return tuple giving line number, offset within line and error code
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 (integer, integer, string)
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 """
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 for name in node.names:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 if not name.asname:
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 continue
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 if self.UppercaseRegexp.match(name.name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 if not self.UppercaseRegexp.match(name.asname):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 yield self.__error(node, "N811")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 elif self.LowercaseRegex.match(name.name):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 if not self.LowercaseRegex.match(name.asname):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 yield self.__error(node, "N812")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 elif self.LowercaseRegex.match(name.asname):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 yield self.__error(node, "N813")
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 elif self.UppercaseRegexp.match(name.asname):
8e4264045fc9 Started implementing a PEP-8 naming checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 yield self.__error(node, "N814")

eric ide

mercurial