Plugins/CheckerPlugins/Pep8/Pep257Checker.py

changeset 2968
b109ff4678bc
parent 2967
f9acd647f881
equal deleted inserted replaced
2967:f9acd647f881 2968:b109ff4678bc
251 self.__repeat = repeat 251 self.__repeat = repeat
252 self.__maxLineLength = maxLineLength 252 self.__maxLineLength = maxLineLength
253 self.__docType = docType 253 self.__docType = docType
254 self.__filename = filename 254 self.__filename = filename
255 self.__source = source[:] 255 self.__source = source[:]
256 self.__isScript = self.__source[0].startswith('#!')
257 256
258 # statistics counters 257 # statistics counters
259 self.counters = {} 258 self.counters = {}
260 259
261 # collection of detected errors 260 # collection of detected errors
761 have a docstring. 760 have a docstring.
762 761
763 @param docstringContext docstring context (Pep257Context) 762 @param docstringContext docstring context (Pep257Context)
764 @param context context of the docstring (Pep257Context) 763 @param context context of the docstring (Pep257Context)
765 """ 764 """
766 if self.__isScript:
767 # assume nothing is exported
768 return
769
770 functionName = context.source()[0].lstrip().split()[1].split("(")[0] 765 functionName = context.source()[0].lstrip().split()[1].split("(")[0]
771 if functionName.startswith('_') and not functionName.endswith('__'): 766 if functionName.startswith('_') and not functionName.endswith('__'):
772 if self.__docType == "eric": 767 if self.__docType == "eric":
773 code = "D203" 768 code = "D203"
774 else: 769 else:
791 have a docstring. 786 have a docstring.
792 787
793 @param docstringContext docstring context (Pep257Context) 788 @param docstringContext docstring context (Pep257Context)
794 @param context context of the docstring (Pep257Context) 789 @param context context of the docstring (Pep257Context)
795 """ 790 """
796 if self.__isScript:
797 # assume nothing is exported
798 return
799
800 className = context.source()[0].lstrip().split()[1].split("(")[0] 791 className = context.source()[0].lstrip().split()[1].split("(")[0]
801 if className.startswith('_'): 792 if className.startswith('_'):
802 if self.__docType == "eric": 793 if self.__docType == "eric":
803 code = "D205" 794 code = "D205"
804 else: 795 else:
965 Private method to check, that docstrings mention the return value type. 956 Private method to check, that docstrings mention the return value type.
966 957
967 @param docstringContext docstring context (Pep257Context) 958 @param docstringContext docstring context (Pep257Context)
968 @param context context of the docstring (Pep257Context) 959 @param context context of the docstring (Pep257Context)
969 """ 960 """
970 if docstringContext is None or self.__isScript: 961 if docstringContext is None:
971 return 962 return
972 963
973 if "return" not in docstringContext.ssource().lower(): 964 if "return" not in docstringContext.ssource().lower():
974 tokens = list( 965 tokens = list(
975 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 966 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1128 if they return anything and don't otherwise. 1119 if they return anything and don't otherwise.
1129 1120
1130 @param docstringContext docstring context (Pep257Context) 1121 @param docstringContext docstring context (Pep257Context)
1131 @param context context of the docstring (Pep257Context) 1122 @param context context of the docstring (Pep257Context)
1132 """ 1123 """
1133 if docstringContext is None or self.__isScript: 1124 if docstringContext is None:
1134 return 1125 return
1135 1126
1136 tokens = list( 1127 tokens = list(
1137 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 1128 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1138 return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) 1129 return_ = [tokens[i + 1][0] for i, token in enumerate(tokens)
1154 @keyparam line for each argument. 1145 @keyparam line for each argument.
1155 1146
1156 @param docstringContext docstring context (Pep257Context) 1147 @param docstringContext docstring context (Pep257Context)
1157 @param context context of the docstring (Pep257Context) 1148 @param context context of the docstring (Pep257Context)
1158 """ 1149 """
1159 if docstringContext is None or self.__isScript: 1150 if docstringContext is None:
1160 return 1151 return
1161 1152
1162 try: 1153 try:
1163 tree = ast.parse(context.ssource()) 1154 tree = ast.parse(context.ssource())
1164 except (SyntaxError, TypeError): 1155 except (SyntaxError, TypeError):
1204 if they raise an exception and don't otherwise. 1195 if they raise an exception and don't otherwise.
1205 1196
1206 @param docstringContext docstring context (Pep257Context) 1197 @param docstringContext docstring context (Pep257Context)
1207 @param context context of the docstring (Pep257Context) 1198 @param context context of the docstring (Pep257Context)
1208 """ 1199 """
1209 if docstringContext is None or self.__isScript: 1200 if docstringContext is None:
1210 return 1201 return
1211 1202
1212 tokens = list( 1203 tokens = list(
1213 tokenize.generate_tokens(StringIO(context.ssource()).readline)) 1204 tokenize.generate_tokens(StringIO(context.ssource()).readline))
1214 exception = [tokens[i + 1][0] for i, token in enumerate(tokens) 1205 exception = [tokens[i + 1][0] for i, token in enumerate(tokens)

eric ide

mercurial