mirror of https://gitlab.com/bashrc2/epicyon
Check that return statements are of the expected type
parent
c504cd3ab7
commit
5c50bd713b
|
@ -507,7 +507,7 @@ def show_qrcode(self, calling_domain: str, path: str,
|
|||
if etag_exists(self, qr_filename):
|
||||
# The file has not changed
|
||||
http_304(self)
|
||||
return
|
||||
return True
|
||||
|
||||
tries = 0
|
||||
media_binary = None
|
||||
|
|
|
@ -700,9 +700,9 @@ def _get_first_item_id(box_json: {}) -> str:
|
|||
"""Returns the id of the first item in the timeline
|
||||
"""
|
||||
if _timeline_is_empty(box_json):
|
||||
return
|
||||
return ''
|
||||
if len(box_json['orderedItems']) == 0:
|
||||
return
|
||||
return ''
|
||||
return box_json['orderedItems'][0]['id']
|
||||
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
|
|||
if debug:
|
||||
print('DEBUG: handle to unfollow ' + handle_to_unfollow +
|
||||
' is not in ' + filename)
|
||||
return
|
||||
return False
|
||||
lines = []
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as fp_unfoll:
|
||||
|
|
|
@ -87,7 +87,7 @@ def _reactionpost(recent_posts_cache: {},
|
|||
return None
|
||||
if not valid_emoji_content(emoji_content):
|
||||
print('_reaction: Invalid emoji reaction: "' + emoji_content + '"')
|
||||
return
|
||||
return None
|
||||
|
||||
full_domain = get_full_domain(domain, port)
|
||||
|
||||
|
|
|
@ -437,11 +437,11 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
|
|||
format for speech synthesis
|
||||
"""
|
||||
if not has_object_dict(post_json_object):
|
||||
return
|
||||
return {}
|
||||
if not post_json_object['object'].get('content'):
|
||||
return
|
||||
return {}
|
||||
if not isinstance(post_json_object['object']['content'], str):
|
||||
return
|
||||
return {}
|
||||
detected_links = []
|
||||
content = urllib.parse.unquote_plus(post_json_object['object']['content'])
|
||||
content = html.unescape(content)
|
||||
|
@ -499,7 +499,7 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
|
|||
speaker_name = \
|
||||
get_display_name(base_dir, actor_url, person_cache)
|
||||
if not speaker_name:
|
||||
return
|
||||
return {}
|
||||
speaker_name = _remove_emoji_from_text(speaker_name)
|
||||
speaker_name = speaker_name.replace('_', ' ')
|
||||
speaker_name = camel_case_split(speaker_name)
|
||||
|
|
26
tests.py
26
tests.py
|
@ -5546,6 +5546,7 @@ def _test_functions():
|
|||
method_name = ''
|
||||
method_args = []
|
||||
module_line = 0
|
||||
curr_return_types = ''
|
||||
for line in lines:
|
||||
module_line += 1
|
||||
# what group is this module in?
|
||||
|
@ -5585,6 +5586,17 @@ def _test_functions():
|
|||
if loc_str not in method_loc:
|
||||
method_loc.append(loc_str)
|
||||
line_count = 0
|
||||
|
||||
# check return statements are of the expected type
|
||||
if curr_return_types and \
|
||||
'"""' not in line and \
|
||||
line.endswith(' return\n'):
|
||||
if curr_return_types != 'None':
|
||||
print(method_name + ' in module ' +
|
||||
mod_name + ' has unexpected return')
|
||||
print('Expected: return ' + curr_return_types)
|
||||
print('Actual: ' + line.strip())
|
||||
assert False
|
||||
prev_line = line
|
||||
continue
|
||||
# reading function def
|
||||
|
@ -5594,6 +5606,14 @@ def _test_functions():
|
|||
# get list of arguments with spaces removed
|
||||
method_args = \
|
||||
source_str.split('def ' + method_name + '(')[1]
|
||||
return_types = method_args.split(')')[1]
|
||||
if ':' in return_types:
|
||||
return_types = return_types.split(':')[0]
|
||||
if '->' in return_types:
|
||||
return_types = return_types.split('->')[1].strip()
|
||||
else:
|
||||
return_types = ''
|
||||
curr_return_types = return_types
|
||||
method_args = method_args.split(')')[0]
|
||||
method_args = method_args.replace(' ', '').split(',')
|
||||
if function.get(mod_name):
|
||||
|
@ -5606,7 +5626,8 @@ def _test_functions():
|
|||
function_properties[method_name] = {
|
||||
"args": method_args,
|
||||
"module": mod_name,
|
||||
"calledInModule": []
|
||||
"calledInModule": [],
|
||||
"returns": return_types
|
||||
}
|
||||
# LOC count for the last function
|
||||
if line_count > 2:
|
||||
|
@ -5684,8 +5705,7 @@ def _test_functions():
|
|||
continue
|
||||
# detect a call to this function
|
||||
if name + '(' in line:
|
||||
mod_list = \
|
||||
properties['calledInModule']
|
||||
mod_list = properties['calledInModule']
|
||||
if mod_name not in mod_list:
|
||||
mod_list.append(mod_name)
|
||||
if mod_name in exclude_func_args:
|
||||
|
|
|
@ -24,7 +24,7 @@ def is_welcome_screen_complete(base_dir: str,
|
|||
"""
|
||||
account_path = acct_dir(base_dir, nickname, domain)
|
||||
if not os.path.isdir(account_path):
|
||||
return
|
||||
return False
|
||||
complete_filename = account_path + '/.welcome_complete'
|
||||
return os.path.isfile(complete_filename)
|
||||
|
||||
|
|
Loading…
Reference in New Issue