def visit_arguments(self, node): """ @node:ast.ast """ #some of the arugments have default values, find them if they do defaultValuedArgs = self._collectDefaultValuedArgs( node.args, node.defaults) self.kwargs = defaultValuedArgs #figure out what the minimum number of params this might take is self.minNumParams = len(node.args) - len(node.defaults) #these are just the regular args without default values for arg in defaultValuedArgs: self.scope.append(defaultValuedArgs[arg]) if node.args: #figure out if the first paramiter is self, if it is then selfParam = self.visit(node.args[0]) if selfParam.name == "self": self.scope.append(selfParam) #reduce the number of min params because self is implicit self.minNumParams -= 1 if ast.get_docstring(self.root): arguments = parseDocString(ast.get_docstring(self.root)) for i in arguments: self.scope.append(i) else: Exceptions.MissingDocStringException(self.name) #it found a * argument, add a tuple to scope with that type, just check to see if it is in scope, if it isn't then riase an exception if node.vararg: try: tupleType = self.scope[node.vararg.arg] #becuase we dont do length tracking, just add in the type and a rept to the end of it. self.starargs.append(tupleType.nextSubType()) self.starargs.append(Bean.VarBean("$rept")) except Exceptions.OutOfScopeException as ex: ex.extraMessage = "The vararg argument " + node.vararg.arg + " was not hinted at in the doc string. Therefore cannot be typed" raise ex #it found a ** argument is found check to see if it is in scope atm. if node.kwarg: try: theKwarg = self.scope[ node.kwarg. arg] #try to look up the keywarg by name out of scope. It may have been placed in by the docstring parser. self.kwargs[theKwarg.name] = theKwarg except Exceptions.OutOfScopeException as ex: ex.extraMessage = "The keyword argument " + node.kwarg.arg + " was not hinted at in the doc string. Therefore cannot be typed" raise ex
def visit_arguments(self, node): """ @node:ast.ast """ #some of the arugments have default values, find them if they do defaultValuedArgs = self._collectDefaultValuedArgs(node.args, node.defaults) self.kwargs = defaultValuedArgs #figure out what the minimum number of params this might take is self.minNumParams = len(node.args) - len(node.defaults) #these are just the regular args without default values for arg in defaultValuedArgs: self.scope.append(defaultValuedArgs[arg]) if node.args: #figure out if the first paramiter is self, if it is then selfParam = self.visit(node.args[0]) if selfParam.name == "self": self.scope.append(selfParam) #reduce the number of min params because self is implicit self.minNumParams -= 1 if ast.get_docstring(self.root): arguments = parseDocString(ast.get_docstring(self.root)) for i in arguments: self.scope.append(i) else: Exceptions.MissingDocStringException(self.name) #it found a * argument, add a tuple to scope with that type, just check to see if it is in scope, if it isn't then riase an exception if node.vararg: try: tupleType = self.scope[node.vararg.arg] #becuase we dont do length tracking, just add in the type and a rept to the end of it. self.starargs.append(tupleType.nextSubType()) self.starargs.append(Bean.VarBean("$rept")) except Exceptions.OutOfScopeException as ex: ex.extraMessage = "The vararg argument " + node.vararg.arg + " was not hinted at in the doc string. Therefore cannot be typed" raise ex #it found a ** argument is found check to see if it is in scope atm. if node.kwarg: try: theKwarg = self.scope[node.kwarg.arg] #try to look up the keywarg by name out of scope. It may have been placed in by the docstring parser. self.kwargs[theKwarg.name] = theKwarg except Exceptions.OutOfScopeException as ex: ex.extraMessage = "The keyword argument " + node.kwarg.arg + " was not hinted at in the doc string. Therefore cannot be typed" raise ex
def _findParamTypes(self): if ast.get_docstring(self.root): return parseDocString(ast.get_docstring(self.root)) else: return []