eric6/Plugins/CheckerPlugins/CodeStyleChecker/AnnotationsChecker.py

Sun, 04 Oct 2020 15:25:17 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 04 Oct 2020 15:25:17 +0200
changeset 7749
285855999b4e
parent 7637
c878e8255972
permissions
-rw-r--r--

Configuration Dialog: optimized the display of the various configuration pages.

7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7247
diff changeset
3 # Copyright (c) 2019 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a checker for function type annotations.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import sys
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import ast
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
7622
384e2aa5c073 Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
13 import AstUtilities
384e2aa5c073 Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
14
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class AnnotationsChecker(object):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class implementing a checker for function type annotations.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Codes = [
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 ## Function Annotations
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 "A001", "A002", "A003",
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 ## Method Annotations
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 "A101", "A102",
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 ## Return Annotations
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 "A201", "A202", "A203", "A204", "A205", "A206",
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
30 ## Annotation Coverage
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
31 "A881",
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
32
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
33 ## Annotation Complexity
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
34 "A891",
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
35
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 ## Syntax Error
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 "A999",
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 ]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
40 def __init__(self, source, filename, select, ignore, expected, repeat,
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
41 args):
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Constructor
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @param source source code to be checked
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @type list of str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param filename name of the source file
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param select list of selected codes
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @type list of str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @param ignore list of codes to be ignored
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @type list of str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @param expected list of expected codes
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @type list of str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @param repeat flag indicating to report each occurrence of a code
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @type bool
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
57 @param args dictionary of arguments for the annotation checks
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
58 @type dict
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__select = tuple(select)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.__ignore = ('',) if select else tuple(ignore)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__expected = expected[:]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.__repeat = repeat
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.__filename = filename
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.__source = source[:]
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
66 self.__args = args
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 # statistics counters
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.counters = {}
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 # collection of detected errors
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.errors = []
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 checkersWithCodes = [
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 (
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__checkFunctionAnnotations,
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 ("A001", "A002", "A003", "A101", "A102",
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 "A201", "A202", "A203", "A204", "A205", "A206",)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 ),
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
80 (self.__checkAnnotationsCoverage, ("A881",)),
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
81 (self.__checkAnnotationComplexity, ("A891",)),
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 ]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
84 self.__defaultArgs = {
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
85 "MinimumCoverage": 75, # % of type annotation coverage
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
86 "MaximumComplexity": 3,
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
87 }
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
88
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__checkers = []
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 for checker, codes in checkersWithCodes:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 if any(not (code and self.__ignoreCode(code))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 for code in codes):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__checkers.append(checker)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 def __ignoreCode(self, code):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 Private method to check if the message code should be ignored.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 @param code message code to check for
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 @return flag indicating to ignore the given code
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 @rtype bool
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 return (code.startswith(self.__ignore) and
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 not code.startswith(self.__select))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 def __error(self, lineNumber, offset, code, *args):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Private method to record an issue.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @param lineNumber line number of the issue
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 @type int
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @param offset position within line of the issue
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @type int
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @param code message code
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @param args arguments for the message
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @type list
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 if self.__ignoreCode(code):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 if code in self.counters:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.counters[code] += 1
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.counters[code] = 1
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 # Don't care about expected codes
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 if code in self.__expected:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 if code and (self.counters[code] == 1 or self.__repeat):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 # record the issue with one based line number
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.errors.append(
7610
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
135 {
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
136 "file": self.__filename,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
137 "line": lineNumber + 1,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
138 "offset": offset,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
139 "code": code,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
140 "args": args,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
141 }
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
142 )
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 def __reportInvalidSyntax(self):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 Private method to report a syntax error.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 exc_type, exc = sys.exc_info()[:2]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if len(exc.args) > 1:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 offset = exc.args[1]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if len(offset) > 2:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 offset = offset[1:3]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 offset = (1, 0)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.__error(offset[0] - 1, offset[1] or 0,
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 'A999', exc_type.__name__, exc.args[0])
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def __generateTree(self):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 Private method to generate an AST for our source.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @return generated AST
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 @rtype ast.Module
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 source = "".join(self.__source)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 return compile(source, self.__filename, 'exec', ast.PyCF_ONLY_AST)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 def run(self):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 Public method to check the given source against annotation issues.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 if not self.__filename:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 # don't do anything, if essential data is missing
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 if not self.__checkers:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 # don't do anything, if no codes were selected
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 try:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__tree = self.__generateTree()
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 except (SyntaxError, TypeError):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.__reportInvalidSyntax()
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 for check in self.__checkers:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 check()
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 def __checkFunctionAnnotations(self):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 Private method to check for function annotation issues.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 visitor = FunctionVisitor(self.__source)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 visitor.visit(self.__tree)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 for issue in visitor.issues:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 node = issue[0]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 reason = issue[1]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 params = issue[2:]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 self.__error(node.lineno - 1, node.col_offset, reason, *params)
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
200
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
201 def __checkAnnotationsCoverage(self):
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
202 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
203 Private method to check for function annotation coverage.
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
204 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
205 minAnnotationsCoverage = self.__args.get(
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
206 "MinimumCoverage", self.__defaultArgs["MinimumCoverage"])
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
207 if minAnnotationsCoverage == 0:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
208 # 0 means it is switched off
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
209 return
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
210
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
211 functionDefs = [
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
212 f for f in ast.walk(self.__tree)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
213 if isinstance(f, (ast.AsyncFunctionDef, ast.FunctionDef))
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
214 ]
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
215 if not functionDefs:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
216 # no functions/methods at all
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
217 return
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
218
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
219 functionDefAnnotationsInfo = [
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
220 hasTypeAnnotations(f) for f in functionDefs
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
221 ]
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
222 annotationsCoverage = int(
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
223 len(list(filter(None, functionDefAnnotationsInfo))) /
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
224 len(functionDefAnnotationsInfo) * 100
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
225 )
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
226 if annotationsCoverage < minAnnotationsCoverage:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
227 self.__error(0, 0, "A881", annotationsCoverage)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
228
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
229 def __checkAnnotationComplexity(self):
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
230 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
231 Private method to check the type annotation complexity.
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
232 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
233 maxAnnotationComplexity = self.__args.get(
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
234 "MaximumComplexity", self.__defaultArgs["MaximumComplexity"])
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
235 typeAnnotations = []
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
236
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
237 functionDefs = [
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
238 f for f in ast.walk(self.__tree)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
239 if isinstance(f, (ast.AsyncFunctionDef, ast.FunctionDef))
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
240 ]
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
241 for functionDef in functionDefs:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
242 typeAnnotations += list(filter(
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
243 None, [a.annotation for a in functionDef.args.args]))
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
244 if functionDef.returns:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
245 typeAnnotations.append(functionDef.returns)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
246 typeAnnotations += [a.annotation for a in ast.walk(self.__tree)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
247 if isinstance(a, ast.AnnAssign) and a.annotation]
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
248 for annotation in typeAnnotations:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
249 complexity = getAnnotationComplexity(annotation)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
250 if complexity > maxAnnotationComplexity:
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
251 self.__error(annotation.lineno - 1, annotation.col_offset,
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
252 "A891", complexity, maxAnnotationComplexity)
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 class FunctionVisitor(ast.NodeVisitor):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 Class implementing a node visitor to check function annotations.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 Note: this class is modelled after flake8-annotations checker.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 def __init__(self, sourceLines):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 Constructor
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 @param sourceLines lines of source code
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 @type list of str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 super(FunctionVisitor, self).__init__()
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 self.__sourceLines = sourceLines
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 self.issues = []
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 def visit_FunctionDef(self, node):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 Public method to handle a function or method definition.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 @param node reference to the node to be processed
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 @type ast.FunctionDef
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 self.__checkFunctionNode(node)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 self.generic_visit(node)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 def visit_AsyncFunctionDef(self, node):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 Public method to handle an async function or method definition.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 @param node reference to the node to be processed
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 @type ast.AsyncFunctionDef
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 self.__checkFunctionNode(node)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 self.generic_visit(node)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 def visit_ClassDef(self, node):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 Public method to handle class definitions.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 @param node reference to the node to be processed
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 @type ast.ClassDef
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 methodNodes = [
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 childNode for childNode in node.body
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 if isinstance(childNode, (ast.FunctionDef, ast.AsyncFunctionDef))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 ]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 for methodNode in methodNodes:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.__checkFunctionNode(methodNode, classMethod=True)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 def __checkFunctionNode(self, node, classMethod=False):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 Private method to check an individual function definition node.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 @param node reference to the node to be processed
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 @type ast.FunctionDef or ast.AsyncFunctionDef
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 @param classMethod flag indicating a class method
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 @type bool
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 if node.name.startswith("__") and node.name.endswith("__"):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 visibilityType = "special"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 elif node.name.startswith("__"):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 visibilityType = "private"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 elif node.name.startswith("_"):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 visibilityType = "protected"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 visibilityType = "public"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 if classMethod:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 decorators = [
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 decorator.id for decorator in node.decorator_list
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 if isinstance(decorator, ast.Name)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 ]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 if "classmethod" in decorators:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 classMethodType = "decorator"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 elif "staticmethod" in decorators:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 classMethodType = "staticmethod"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 classMethodType = ""
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 classMethodType = "function"
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 # check argument annotations
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 for argType in ("args", "vararg", "kwonlyargs", "kwarg"):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 args = node.args.__getattribute__(argType)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 if args:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 if not isinstance(args, list):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 args = [args]
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 for arg in args:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 if not arg.annotation:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 self.__classifyArgumentError(
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 arg, argType, classMethodType)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 # check function return annotation
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 if not node.returns:
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
354 lineno = node.lineno
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
355 colOffset = self.__sourceLines[lineno - 1].rfind(":") + 1
7246
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 self.__classifyReturnError(classMethodType, visibilityType,
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 lineno, colOffset)
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 def __classifyReturnError(self, methodType, visibilityType, lineno,
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 colOffset):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 Private method to classify and record a return annotation issue.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 @param methodType type of method/function the argument belongs to
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 @param visibilityType visibility of the function
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 @param lineno line number
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 @type int
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 @param colOffset column number
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 @type int
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 # create a dummy AST node to report line and column
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 node = ast.AST()
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 node.lineno = lineno
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 node.col_offset = colOffset
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 # now classify the issue
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 if methodType == "classmethod":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 self.issues.append((node, "A206"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 elif methodType == "staticmethod":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 self.issues.append((node, "A205"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 elif visibilityType == "special":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self.issues.append((node, "A204"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 elif visibilityType == "private":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 self.issues.append((node, "A203"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 elif visibilityType == "protected":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 self.issues.append((node, "A202"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 self.issues.append((node, "A201"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 def __classifyArgumentError(self, argNode, argType, methodType):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 Private method to classify and record an argument annotation issue.
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 @param argNode reference to the argument node
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 @type ast.arguments
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 @param argType type of the argument node
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 @param methodType type of method/function the argument belongs to
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 @type str
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 # check class method issues
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 if methodType != "function":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 if argNode.arg in ("cls", "self"):
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 if methodType == "classmethod":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 self.issues.append((argNode, "A102"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 elif methodType != "staticmethod":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 self.issues.append((argNode, "A101"))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 return
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 # check all other arguments
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 if argType == "kwarg":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 self.issues.append((argNode, "A003", argNode.arg))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 elif argType == "vararg":
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 self.issues.append((argNode, "A002", argNode.arg))
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 else:
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 # args and kwonlyargs
c32a350d2414 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 self.issues.append((argNode, "A001", argNode.arg))
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
421
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
422 ######################################################################
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
423 ## some utility functions below
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
424 ######################################################################
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
425
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
426
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
427 def hasTypeAnnotations(funcNode):
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
428 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
429 Function to check for type annotations.
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
430
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
431 @param funcNode reference to the function definition node to be checked
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
432 @type ast.AsyncFunctionDef or ast.FunctionDef
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
433 @return flag indicating the presence of type annotations
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
434 @rtype bool
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
435 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
436 hasReturnAnnotation = funcNode.returns is not None
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
437 hasArgsAnnotations = any(a for a in funcNode.args.args
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
438 if a.annotation is not None)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
439 hasKwargsAnnotations = (funcNode.args and
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
440 funcNode.args.kwarg and
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
441 funcNode.args.kwarg.annotation is not None)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
442 hasKwonlyargsAnnotations = any(a for a in funcNode.args.kwonlyargs
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
443 if a.annotation is not None)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
444
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
445 return any((hasReturnAnnotation, hasArgsAnnotations, hasKwargsAnnotations,
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
446 hasKwonlyargsAnnotations))
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
447
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
448
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
449 def getAnnotationComplexity(annotationNode):
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
450 """
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
451 Function to determine the annotation complexity.
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
452
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
453 @param annotationNode reference to the node to determine the annotation
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
454 complexity for
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
455 @type ast.AST
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
456 @return annotation complexity
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
457 @rtype = int
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
458 """
7622
384e2aa5c073 Code Style Checker: continued to implement checker for security related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
459 if AstUtilities.isString(annotationNode):
7247
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
460 annotationNode = ast.parse(annotationNode.s).body[0].value
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
461 if isinstance(annotationNode, ast.Subscript):
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
462 return 1 + getAnnotationComplexity(annotationNode.slice.value)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
463 if isinstance(annotationNode, ast.Tuple):
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
464 return max(getAnnotationComplexity(n) for n in annotationNode.elts)
bf9379f964f3 Code Style Checker:
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7246
diff changeset
465 return 1

eric ide

mercurial