def search_params(evaluator, execution_context, funcdef): """ A dynamic search for param values. If you try to complete a type: >>> def func(foo): ... foo >>> func(1) >>> func("") It is not known what the type ``foo`` without analysing the whole code. You have to look for all calls to ``func`` to find out what ``foo`` possibly is. """ if not settings.dynamic_params: return create_default_params(execution_context, funcdef) evaluator.dynamic_params_depth += 1 try: path = execution_context.get_root_context().py__file__() if path is not None and is_stdlib_path(path): # We don't want to search for usages in the stdlib. Usually people # don't work with it (except if you are a core maintainer, sorry). # This makes everything slower. Just disable it and run the tests, # you will see the slowdown, especially in 3.6. return create_default_params(execution_context, funcdef) if funcdef.type == 'lambdef': string_name = _get_lambda_name(funcdef) if string_name is None: return create_default_params(execution_context, funcdef) else: string_name = funcdef.name.value debug.dbg('Dynamic param search in %s.', string_name, color='MAGENTA') try: module_context = execution_context.get_root_context() function_executions = _search_function_executions( evaluator, module_context, funcdef, string_name=string_name, ) if function_executions: zipped_params = zip(*list( function_execution.get_params() for function_execution in function_executions)) params = [ MergedExecutedParams(executed_params) for executed_params in zipped_params ] # Evaluate the ExecutedParams to types. else: return create_default_params(execution_context, funcdef) finally: debug.dbg('Dynamic param result finished', color='MAGENTA') return params finally: evaluator.dynamic_params_depth -= 1
def search_params(evaluator, execution_context, funcdef): """ A dynamic search for param values. If you try to complete a type: >>> def func(foo): ... foo >>> func(1) >>> func("") It is not known what the type ``foo`` without analysing the whole code. You have to look for all calls to ``func`` to find out what ``foo`` possibly is. """ if not settings.dynamic_params: return create_default_params(execution_context, funcdef) evaluator.dynamic_params_depth += 1 try: path = execution_context.get_root_context().py__file__() if path is not None and is_stdlib_path(path): # We don't want to search for usages in the stdlib. Usually people # don't work with it (except if you are a core maintainer, sorry). # This makes everything slower. Just disable it and run the tests, # you will see the slowdown, especially in 3.6. return create_default_params(execution_context, funcdef) if funcdef.type == 'lambdef': string_name = _get_lambda_name(funcdef) if string_name is None: return create_default_params(execution_context, funcdef) else: string_name = funcdef.name.value debug.dbg('Dynamic param search in %s.', string_name, color='MAGENTA') try: module_context = execution_context.get_root_context() function_executions = _search_function_executions( evaluator, module_context, funcdef, string_name=string_name, ) if function_executions: zipped_params = zip(*list( function_execution.get_params() for function_execution in function_executions )) params = [MergedExecutedParams(executed_params) for executed_params in zipped_params] # Evaluate the ExecutedParams to types. else: return create_default_params(execution_context, funcdef) finally: debug.dbg('Dynamic param result finished', color='MAGENTA') return params finally: evaluator.dynamic_params_depth -= 1