diff --git a/builtin.py b/builtin.py index 0725a8b9..229b3faf 100644 --- a/builtin.py +++ b/builtin.py @@ -5,6 +5,9 @@ import os import debug import parsing +module_find_path = sys.path[1:] + + class CachedModule(object): cache = {} @@ -32,7 +35,7 @@ class CachedModule(object): def _load_module(self): source = self._get_source() - self._parser = parsing.PyFuzzyParser(source, self.name) + self._parser = parsing.PyFuzzyParser(source, self.path or self.name) #except: # debug.warning('not possible to resolve', self.name, source) #open('builtin_fail', 'w').write(code) @@ -70,7 +73,7 @@ class Parser(CachedModule): } module_cache = {} - def __init__(self, path=None, name=None, sys_path=sys.path): + def __init__(self, path=None, name=None, sys_path=module_find_path): if not name: name = os.path.basename(path) name = name.rpartition('.')[0] # cut file type (normally .so) @@ -116,7 +119,7 @@ class Parser(CachedModule): positions = [m.start() for m in matches] for i, pos in enumerate(positions): try: - code_block = code[pos:positions[i+1]] + code_block = code[pos:positions[i + 1]] except IndexError: code_block = code[pos:len(code)] structure_name = matches[i].group(1) @@ -125,7 +128,7 @@ class Parser(CachedModule): self.mixin_funcs[name] = code_block else: raise NotImplementedError - print code_block + #print code_block def _generate_code(self, scope, depth=0): """ diff --git a/evaluate.py b/evaluate.py index bff788f2..2efa9f04 100644 --- a/evaluate.py +++ b/evaluate.py @@ -99,6 +99,7 @@ class Executable(object): calls.keys = keys calls.type = array_type new_param = copy.copy(param) + new_param.parent = self.var_args.parent_stmt new_param._assignment_calls_calculated = True new_param._assignment_calls = calls name = copy.copy(param.get_name()) @@ -400,6 +401,9 @@ class Execution(Executable): if isinstance(self.base, Class): # there maybe executions of executions stmts = [Instance(self.base, self.var_args)] + elif isinstance(self.base, Generator): + return Execution(self.base.func).get_return_types(True) + pass else: func = self.process_decorators() @@ -407,7 +411,7 @@ class Execution(Executable): # don't do this with exceptions, as usual, because some deeper # exceptions could be catched - and I wouldn't know what happened. if hasattr(func, 'returns'): - if func.is_generator: + if func.is_generator and not evaluate_generator: return [Generator(func)] else: self.set_param_cb(func) @@ -438,13 +442,27 @@ class Execution(Executable): class Generator(object): - def __init__(self, execution): + def __init__(self, func): super(Generator, self).__init__() - self.execution = execution + self.func = func def get_defined_names(self): - return [] + """ + Returns a list of GeneratorObject, which can return the content of a + generator + """ + names = [] + for n in ['__next__', 'send']: + # the name for the `next` function + name = parsing.Name([n], 0, 0, 0) + name.parent = self + names.append(name) + return names + + @property + def parent(self): # TODO add generator names (__next__, send, close, throw, next?) + return self.func.parent #self.execution.get_return_types() @@ -526,10 +544,6 @@ class ArrayElement(object): def parent(self): raise NotImplementedError("This shouldn't happen") - @property - def returns(self): - return self.name.parent.returns - @property def names(self): return self.name.names @@ -822,7 +836,7 @@ def follow_call(scope, call): # reset the position, when imports where stripped position = None - debug.dbg('call before result %s, current %s, scope %s' + debug.dbg('call before result %s, current "%s", scope %s' % (result, current, scope)) result = follow_paths(path, result, position=position) diff --git a/ftest.py b/ftest.py index a6945312..f92edca5 100755 --- a/ftest.py +++ b/ftest.py @@ -5,7 +5,7 @@ import functions functions.debug.debug_function = functions.debug.print_to_stdout functions.debug.ignored_modules = ['parsing', 'builtin'] #functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules'] -functions.modules.module_find_path.insert(0, '.') +functions.modules.builtin.module_find_path.insert(0, '.') f_name = 'parsetest.py' #f_name = 'test/completion/classes.py' diff --git a/mixin/__builtin__.py b/mixin/__builtin__.py index e39b76dc..8d92240d 100644 --- a/mixin/__builtin__.py +++ b/mixin/__builtin__.py @@ -1,5 +1,5 @@ -def next(iterator, default=None): +def next(iterator, default=1): if hasattr("next"): return iterator.next() else: diff --git a/modules.py b/modules.py index 8bc3883a..135c282a 100644 --- a/modules.py +++ b/modules.py @@ -1,5 +1,4 @@ import imp -import sys import os import debug @@ -8,7 +7,6 @@ import builtin files = {} load_module_cb = None -module_find_path = sys.path[1:] class ModuleNotFound(Exception): @@ -64,12 +62,12 @@ def find_module(current_module, point_path): i = imp.find_module(string, path) except ImportError: # find builtins (ommit path): - i = imp.find_module(string, module_find_path) + i = imp.find_module(string, builtin.module_find_path) return i # TODO handle relative paths - they are included in the import object current_namespace = None - module_find_path.insert(0, os.path.dirname(current_module.path)) + builtin.module_find_path.insert(0, os.path.dirname(current_module.path)) # now execute those paths rest = [] for i, s in enumerate(point_path): @@ -82,7 +80,7 @@ def find_module(current_module, point_path): raise ModuleNotFound( 'The module you searched has not been found') - module_find_path.pop(0) + builtin.module_find_path.pop(0) path = current_namespace[1] is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY diff --git a/parsetest.py b/parsetest.py index 8354b376..dbd5d8a0 100644 --- a/parsetest.py +++ b/parsetest.py @@ -164,17 +164,17 @@ def gen(): gen_exe = gen() -def dec(func): - def wrapper(*args, **kwargs): - return func(dict, *args, **kwargs) - return wrapper +def nexti(iterator, default=list): + if hasattr("next"): + #return iterator.next() + else: + return iterator.__next__() + #return default -@dec -def fu(a, b, c, *args, **kwargs): - return a, b, c, args, kwargs -exe = fu(list, c=set, d='') +#from temp import * + #exe[0]. #exe[4]['d'] -gen_exe. +next(gen_exe). diff --git a/test/completion/functions.py b/test/completion/functions.py index 0a9c9195..ab0b2f84 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -236,6 +236,8 @@ def gen(): yield 1 yield "" -exe = next(gen()) +gen_exe = gen() #? ['upper'] -exe.upper +next(gen_exe).upper +#? ['real'] +next(gen_exe).real diff --git a/test/run.py b/test/run.py index e64c1db1..24506422 100755 --- a/test/run.py +++ b/test/run.py @@ -5,7 +5,8 @@ import re import StringIO import traceback -sys.path.append('../') +os.chdir('../') +sys.path.append('.') import functions #functions.set_debug_function(functions.debug.print_to_stdout) @@ -58,10 +59,14 @@ def completion_test(source): # reset the test, if only one specific test is wanted if len(sys.argv) > 2 and line_nr != int(sys.argv[2]): correct = None + import debug + debug.debug_function = \ + functions.debug.print_to_stdout + debug.ignored_modules = ['parsing', 'builtin'] return tests, fails # completion tests: -completion_test_dir = 'completion' +completion_test_dir = 'test/completion' summary = [] for f_name in os.listdir(completion_test_dir): if len(sys.argv) == 1 or [a for a in sys.argv[1:] if a in f_name]: