49 else: |
49 else: |
50 self.__source = source[:] |
50 self.__source = source[:] |
51 self.__start = startLine |
51 self.__start = startLine |
52 self.__indent = "" |
52 self.__indent = "" |
53 self.__type = contextType |
53 self.__type = contextType |
|
54 self.__special = "" |
54 |
55 |
55 # ensure first line is left justified |
56 # ensure first line is left justified |
56 if self.__source: |
57 if self.__source: |
57 self.__indent = self.__source[0].replace( |
58 self.__indent = self.__source[0].replace( |
58 self.__source[0].lstrip(), "") |
59 self.__source[0].lstrip(), "") |
103 Public method to get the context type. |
104 Public method to get the context type. |
104 |
105 |
105 @return context type (string) |
106 @return context type (string) |
106 """ |
107 """ |
107 return self.__type |
108 return self.__type |
|
109 |
|
110 def setSpecial(self, special): |
|
111 """ |
|
112 Public method to set a special attribute for the context. |
|
113 |
|
114 @param special attribute string |
|
115 @type str |
|
116 """ |
|
117 self.__special = special |
|
118 |
|
119 def special(self): |
|
120 """ |
|
121 Public method to get the special context attribute string. |
|
122 |
|
123 @return attribute string |
|
124 @rtype str |
|
125 """ |
|
126 return self.__special |
108 |
127 |
109 |
128 |
110 class DocStyleChecker(object): |
129 class DocStyleChecker(object): |
111 """ |
130 """ |
112 Class implementing a checker for documentation string conventions. |
131 Class implementing a checker for documentation string conventions. |
617 kind, value, (line, char), _, _ = \ |
636 kind, value, (line, char), _, _ = \ |
618 self.__skipIndentedBlock(tokenGenerator) |
637 self.__skipIndentedBlock(tokenGenerator) |
619 end = line - 1, char |
638 end = line - 1, char |
620 startLine = classContext.start() + start[0] |
639 startLine = classContext.start() + start[0] |
621 endLine = classContext.start() + end[0] |
640 endLine = classContext.start() + end[0] |
622 contexts.append(DocStyleContext( |
641 context = DocStyleContext( |
623 self.__source[startLine:endLine], |
642 self.__source[startLine:endLine], |
624 startLine, "def")) |
643 startLine, "def") |
|
644 if startLine > 0: |
|
645 if self.__source[startLine - 1].strip() == \ |
|
646 "@staticmethod": |
|
647 context.setSpecial("staticmethod") |
|
648 elif self.__source[startLine - 1].strip() == \ |
|
649 "@classmethod": |
|
650 context.setSpecial("classmethod") |
|
651 contexts.append(context) |
625 except StopIteration: |
652 except StopIteration: |
626 pass |
653 pass |
627 self.__methodsCache = contexts |
654 self.__methodsCache = contexts |
628 |
655 |
629 return self.__methodsCache |
656 return self.__methodsCache |
1363 elif functionName.startswith('_') or \ |
1390 elif functionName.startswith('_') or \ |
1364 functionName.endswith('Event'): |
1391 functionName.endswith('Event'): |
1365 if firstWord != 'protected': |
1392 if firstWord != 'protected': |
1366 self.__error(docstringContext.start() + lineNumber, 0, |
1393 self.__error(docstringContext.start() + lineNumber, 0, |
1367 "D232", 'protected') |
1394 "D232", 'protected') |
1368 elif arguments.startswith(('cls,', 'cls)')): |
1395 elif arguments.startswith(('cls,', 'cls)')) or \ |
|
1396 context.special() == "classmethod": |
1369 if firstWord != 'class': |
1397 if firstWord != 'class': |
1370 self.__error(docstringContext.start() + lineNumber, 0, |
1398 self.__error(docstringContext.start() + lineNumber, 0, |
1371 "D232", 'class') |
1399 "D232", 'class') |
|
1400 elif context.special() == "staticmethod": |
|
1401 if firstWord != 'static': |
|
1402 self.__error(docstringContext.start() + lineNumber, 0, |
|
1403 "D232", 'static') |
1372 else: |
1404 else: |
1373 if firstWord != 'public': |
1405 if firstWord != 'public': |
1374 self.__error(docstringContext.start() + lineNumber, 0, |
1406 self.__error(docstringContext.start() + lineNumber, 0, |
1375 "D232", 'public') |
1407 "D232", 'public') |
1376 |
1408 |