From f4a972fd1ffb3e9333436b2bda5a26b3b45e6112 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Aug 2022 12:13:37 +0100 Subject: [PATCH 1/2] Comments --- tests.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index ab107561d..0d1eb1924 100644 --- a/tests.py +++ b/tests.py @@ -4757,7 +4757,7 @@ def get_function_calls(name: str, lines: [], start_line_ctr: int, def _function_args_match(call_args: [], func_args: []): - """Do the function artuments match the function call arguments + """Do the function arguments match the function call arguments """ if len(call_args) == len(func_args): return True @@ -5213,20 +5213,24 @@ def _test_functions(): for _, _, files in os.walk('.'): for source_file in files: + # is this really a source file? if not source_file.endswith('.py'): continue if source_file.startswith('.#'): continue if source_file.startswith('flycheck_'): continue + # get the module name mod_name = source_file.replace('.py', '') modules[mod_name] = { 'functions': [] } + # load the module source source_str = '' with open(source_file, 'r', encoding='utf-8') as fp_src: source_str = fp_src.read() modules[mod_name]['source'] = source_str + # go through the source line by line with open(source_file, 'r', encoding='utf-8') as fp_src: lines = fp_src.readlines() modules[mod_name]['lines'] = lines @@ -5234,6 +5238,7 @@ def _test_functions(): prev_line = 'start' method_name = '' for line in lines: + # what group is this module in? if '__module_group__' in line: if '=' in line: group_name = line.split('=')[1].strip() @@ -5245,6 +5250,7 @@ def _test_functions(): else: if mod_name not in mod_groups[group_name]: mod_groups[group_name].append(mod_name) + # reading function lines if not line.strip().startswith('def '): if line_count > 0: line_count += 1 @@ -5266,9 +5272,11 @@ def _test_functions(): line_count = 0 prev_line = line continue + # reading function def prev_line = line line_count = 1 method_name = line.split('def ', 1)[1].split('(')[0] + # get list of arguments with spaces removed method_args = \ source_str.split('def ' + method_name + '(')[1] method_args = method_args.split(')')[0] @@ -5279,6 +5287,7 @@ def _test_functions(): function[mod_name] = [method_name] if method_name not in modules[mod_name]['functions']: modules[mod_name]['functions'].append(method_name) + # create an entry for this function function_properties[method_name] = { "args": method_args, "module": mod_name, @@ -5358,6 +5367,7 @@ def _test_functions(): if line_str.startswith('class '): line_ctr += 1 continue + # detect a call to this function if name + '(' in line: mod_list = \ function_properties[name]['calledInModule'] @@ -5369,11 +5379,14 @@ def _test_functions(): if name in exclude_funcs: line_ctr += 1 continue + # get the function call arguments call_args = \ _get_function_call_args(name, modules[mod_name]['lines'], line_ctr) + # get the function def arguments func_args = function_properties[name]['args'] + # match the call arguments to the definition arguments if not _function_args_match(call_args, func_args): print('Call to function ' + name + ' does not match its arguments') From bde867916392723c5004351f8bb391a82622d209 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Aug 2022 12:22:19 +0100 Subject: [PATCH 2/2] Function return type --- tests.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 0d1eb1924..99bbc38d2 100644 --- a/tests.py +++ b/tests.py @@ -4756,13 +4756,13 @@ def get_function_calls(name: str, lines: [], start_line_ctr: int, return calls_functions -def _function_args_match(call_args: [], func_args: []): - """Do the function arguments match the function call arguments +def _function_args_match(call_args: [], func_args: []) -> bool: + """Do the function arguments match the function call arguments? """ if len(call_args) == len(func_args): return True - # count non-optional arguments + # count non-optional arguments in function call call_args_ctr = 0 for arg1 in call_args: if arg1 == 'self': @@ -4770,6 +4770,7 @@ def _function_args_match(call_args: [], func_args: []): if '=' not in arg1 or arg1.startswith("'"): call_args_ctr += 1 + # count non-optional arguments in function def func_args_ctr = 0 for arg2 in func_args: if arg2 == 'self':