def main(argv): import getopt def usage(): print 'usage: %s [-d] [-q] [-a] [-i iteration] [-c config] [-C key=val] [-D] [-p pythonpath] [-P stubpath] [-o output] [-t format] [file ...]' % argv[0] return 100 try: (opts, args) = getopt.getopt(argv[1:], 'dqai:c:CDp:P:o:t:') except getopt.GetoptError: return usage() if not args: return usage() stubdir = os.path.join(os.path.dirname(pyntch.__file__), 'stub') debug = 0 defaultpath = True showall = False format = 'txt' verbose = 1 iteration = sys.maxint modpath = [] stubpath = [stubdir] output = None for (k, v) in opts: if k == '-d': debug += 1 elif k == '-q': verbose -= 1 elif k == '-a': showall = True elif k == '-i': iteration = int(v) elif k == '-c': ErrorConfig.load(v) elif k == '-C': (k,v) = v.split('=') ErrorConfig.set(k, eval(v)) elif k == '-D': defaultpath = False elif k == '-p': modpath.extend(v.split(':')) elif k == '-P': stubpath.extend(v.split(':')) elif k == '-o': output = v if v.endswith('.xml'): format = 'xml' elif k == '-t': format = v if defaultpath: modpath.extend(sys.path) TypeNode.debug = debug TypeNode.verbose = verbose Interpreter.debug = debug Interpreter.verbose = verbose Interpreter.initialize(stubpath) TypeChecker.reset() MustBeDefinedNode.reset() ExceptionCatcher.reset() t = time.time() modules = [] for name in args: try: if name.endswith('.py'): path = name (name,_) = os.path.splitext(os.path.basename(name)) modules.append(Interpreter.load_file(name, path, modpath)) else: modules.append(Interpreter.load_module(name, modpath)[-1]) except ModuleNotFound, e: print >>sys.stderr, 'module not found:', name
def process_args_nokwd(self, frame, anchor, args): checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0') args[0].connect(checker.recv) checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 1') args[1].connect(checker.recv) obj = CompoundTypeNode(args) return TupleType.create_tuple([obj, obj])
def process_args_nokwd(self, frame, anchor, args): checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0') args[0].connect(checker.recv) checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 1') args[1].connect(checker.recv) if 3 <= len(args): checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 2') args[2].connect(checker.recv) return CompoundTypeNode(args)
def __init__(self, frame, anchor, spec): self.checker = TypeChecker(frame, [TypeType.get_typeobj()], 'typespec') self.tuplechecker = SequenceTypeChecker(frame, anchor, [TypeType.get_typeobj()], 'typespec') CompoundTypeNode.__init__(self) spec.connect(self.recv) return
def call(self, frame, anchor, args, kwargs): from pyntch.config import ErrorConfig if len(args) == 0: frame.raise_expt(ErrorConfig.InvalidNumOfArgs(1, len(args))) return UndefinedTypeNode.get_object() arg0checker = TypeChecker(frame, [self.klass], 'arg0') args[0].connect(arg0checker.recv) return self.func.call(frame, anchor, args, kwargs)
def recv(self, src): from pyntch.expression import OptMethodCall for obj in src: if obj in self.received: continue self.received.add(obj) if isinstance(obj, InstanceObject): value = OptMethodCall(self.frame, self.anchor, obj, '__str__') checker = TypeChecker( self.frame, BaseStringType.get_typeobj(), 'the return value of __str__ method') value.connect(checker.recv) value = OptMethodCall(self.frame, self.anchor, obj, '__repr__') checker = TypeChecker( self.frame, BaseStringType.get_typeobj(), 'the return value of __repr__ method') value.connect(checker.recv) return
def recv_fcmp(self, src): for obj in src: if obj in self.received_fcmp: continue self.received_fcmp.add(obj) try: checker = TypeChecker( self.frame, IntType.get_typeobj(), 'the return value of comparison function') obj.call(self.frame, self.anchor, (self.key, self.key), {}).connect(checker.recv) except NodeTypeError: self.frame.raise_expt(ErrorConfig.NotCallable(obj)) return
def process_args_nokwd(self, frame, anchor, args): checker = TypeChecker(frame, [NumberType.get_typeobj()], 'arg 0') args[0].connect(checker.recv) return args[0]
def main(argv): import getopt def usage(): print 'usage: %s [-d] [-q] [-a] [-i iteration] [-c config] [-C key=val] [-D] [-p pythonpath] [-P stubpath] [-o output] [-t format] [file ...]' % argv[ 0] return 100 try: (opts, args) = getopt.getopt(argv[1:], 'dqai:c:CDp:P:o:t:') except getopt.GetoptError: return usage() if not args: return usage() stubdir = os.path.join(os.path.dirname(pyntch.__file__), 'stub') debug = 0 defaultpath = True showall = False format = 'txt' verbose = 1 iteration = sys.maxint modpath = [] stubpath = [stubdir] output = None for (k, v) in opts: if k == '-d': debug += 1 elif k == '-q': verbose -= 1 elif k == '-a': showall = True elif k == '-i': iteration = int(v) elif k == '-c': ErrorConfig.load(v) elif k == '-C': (k, v) = v.split('=') ErrorConfig.set(k, eval(v)) elif k == '-D': defaultpath = False elif k == '-p': modpath.extend(v.split(':')) elif k == '-P': stubpath.extend(v.split(':')) elif k == '-o': output = v if v.endswith('.xml'): format = 'xml' elif k == '-t': format = v if defaultpath: modpath.extend(sys.path) TypeNode.debug = debug TypeNode.verbose = verbose Interpreter.debug = debug Interpreter.verbose = verbose Interpreter.initialize(stubpath) TypeChecker.reset() MustBeDefinedNode.reset() ExceptionCatcher.reset() t = time.time() modules = [] for name in args: try: if name.endswith('.py'): path = name (name, _) = os.path.splitext(os.path.basename(name)) modules.append(Interpreter.load_file(name, path, modpath)) else: modules.append(Interpreter.load_module(name, modpath)[-1]) except ModuleNotFound, e: print >> sys.stderr, 'module not found:', name
try: if name.endswith('.py'): path = name (name, _) = os.path.splitext(os.path.basename(name)) modules.append(Interpreter.load_file(name, path, modpath)) else: modules.append(Interpreter.load_module(name, modpath)[-1]) except ModuleNotFound, e: print >> sys.stderr, 'module not found:', name if showall: modules = Interpreter.get_all_modules() if ErrorConfig.unfound_modules: print >> sys.stderr, 'modules not found:', ', '.join( sorted(ErrorConfig.unfound_modules)) TypeNode.run(iteration=iteration) TypeChecker.check() MustBeDefinedNode.check() ExceptionCatcher.check() TypeNode.run(iteration=iteration) if verbose: print >> sys.stderr, ( 'total files=%d, lines=%d in %.2fsec' % (Interpreter.files, Interpreter.lines, time.time() - t)) outfp = sys.stdout if output: outfp = file(output, 'w') strm = IndentedStream(outfp) if format == 'xml': strm.write('<output>') for module in modules: if format == 'xml': module.showxml(strm)
for name in args: try: if name.endswith('.py'): path = name (name,_) = os.path.splitext(os.path.basename(name)) modules.append(Interpreter.load_file(name, path, modpath)) else: modules.append(Interpreter.load_module(name, modpath)[-1]) except ModuleNotFound, e: print >>sys.stderr, 'module not found:', name if showall: modules = Interpreter.get_all_modules() if ErrorConfig.unfound_modules: print >>sys.stderr, 'modules not found:', ', '.join(sorted(ErrorConfig.unfound_modules)) TypeNode.run(iteration=iteration) TypeChecker.check() MustBeDefinedNode.check() ExceptionCatcher.check() TypeNode.run(iteration=iteration) if verbose: print >>sys.stderr, ('total files=%d, lines=%d in %.2fsec' % (Interpreter.files, Interpreter.lines, time.time()-t)) outfp = sys.stdout if output: outfp = file(output, 'w') strm = IndentedStream(outfp) if format == 'xml': strm.write('<output>') for module in modules: if format == 'xml': module.showxml(strm) else:
def setup(self, frame, validtypes, blame=None): TypeChecker.__init__(self, frame, validtypes, blame or repr(self)) return