UtilitiesPython2/Pep257CheckerPy2.py

changeset 2968
b109ff4678bc
parent 2967
f9acd647f881
equal deleted inserted replaced
2967:f9acd647f881 2968:b109ff4678bc
140 self.__repeat = repeat 140 self.__repeat = repeat
141 self.__maxLineLength = maxLineLength 141 self.__maxLineLength = maxLineLength
142 self.__docType = docType 142 self.__docType = docType
143 self.__filename = filename 143 self.__filename = filename
144 self.__source = source[:] 144 self.__source = source[:]
145 self.__isScript = self.__source[0].startswith('#!')
146 145
147 # statistics counters 146 # statistics counters
148 self.counters = {} 147 self.counters = {}
149 148
150 # collection of detected errors 149 # collection of detected errors
629 have a docstring. 628 have a docstring.
630 629
631 @param docstringContext docstring context (Pep257Context) 630 @param docstringContext docstring context (Pep257Context)
632 @param context context of the docstring (Pep257Context) 631 @param context context of the docstring (Pep257Context)
633 """ 632 """
634 if self.__isScript:
635 # assume nothing is exported
636 return
637
638 functionName = context.source()[0].lstrip().split()[1].split("(")[0] 633 functionName = context.source()[0].lstrip().split()[1].split("(")[0]
639 if functionName.startswith('_') and not functionName.endswith('__'): 634 if functionName.startswith('_') and not functionName.endswith('__'):
640 if self.__docType == "eric": 635 if self.__docType == "eric":
641 code = "D203" 636 code = "D203"
642 else: 637 else:
659 have a docstring. 654 have a docstring.
660 655
661 @param docstringContext docstring context (Pep257Context) 656 @param docstringContext docstring context (Pep257Context)
662 @param context context of the docstring (Pep257Context) 657 @param context context of the docstring (Pep257Context)
663 """ 658 """
664 if self.__isScript:
665 # assume nothing is exported
666 return
667
668 className = context.source()[0].lstrip().split()[1].split("(")[0] 659 className = context.source()[0].lstrip().split()[1].split("(")[0]
669 if className.startswith('_'): 660 if className.startswith('_'):
670 if self.__docType == "eric": 661 if self.__docType == "eric":
671 code = "D205" 662 code = "D205"
672 else: 663 else:
833 Private method to check, that docstrings mention the return value type. 824 Private method to check, that docstrings mention the return value type.
834 825
835 @param docstringContext docstring context (Pep257Context) 826 @param docstringContext docstring context (Pep257Context)
836 @param context context of the docstring (Pep257Context) 827 @param context context of the docstring (Pep257Context)
837 """ 828 """
838 if docstringContext is None or self.__isScript: 829 if docstringContext is None:
839 return 830 return
840 831
841 if "return" not in docstringContext.ssource().lower(): 832 if "return" not in docstringContext.ssource().lower():
842 tokens = list( 833 tokens = list(
843 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 834 tokenize.generate_tokens(StringIO(context.ssource()).readline))
996 if they return anything and don't otherwise. 987 if they return anything and don't otherwise.
997 988
998 @param docstringContext docstring context (Pep257Context) 989 @param docstringContext docstring context (Pep257Context)
999 @param context context of the docstring (Pep257Context) 990 @param context context of the docstring (Pep257Context)
1000 """ 991 """
1001 if docstringContext is None or self.__isScript: 992 if docstringContext is None:
1002 return 993 return
1003 994
1004 tokens = list( 995 tokens = list(
1005 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 996 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1006 return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) 997 return_ = [tokens[i + 1][0] for i, token in enumerate(tokens)
1022 @keyparam line for each argument. 1013 @keyparam line for each argument.
1023 1014
1024 @param docstringContext docstring context (Pep257Context) 1015 @param docstringContext docstring context (Pep257Context)
1025 @param context context of the docstring (Pep257Context) 1016 @param context context of the docstring (Pep257Context)
1026 """ 1017 """
1027 if docstringContext is None or self.__isScript: 1018 if docstringContext is None:
1028 return 1019 return
1029 1020
1030 try: 1021 try:
1031 tree = ast.parse(context.ssource()) 1022 tree = ast.parse(context.ssource())
1032 except (SyntaxError, TypeError): 1023 except (SyntaxError, TypeError):
1072 if they raise an exception and don't otherwise. 1063 if they raise an exception and don't otherwise.
1073 1064
1074 @param docstringContext docstring context (Pep257Context) 1065 @param docstringContext docstring context (Pep257Context)
1075 @param context context of the docstring (Pep257Context) 1066 @param context context of the docstring (Pep257Context)
1076 """ 1067 """
1077 if docstringContext is None or self.__isScript: 1068 if docstringContext is None:
1078 return 1069 return
1079 1070
1080 tokens = list( 1071 tokens = list(
1081 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 1072 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1082 exception = [tokens[i + 1][0] for i, token in enumerate(tokens) 1073 exception = [tokens[i + 1][0] for i, token in enumerate(tokens)

eric ide

mercurial