【发布时间】:2021-11-11 15:05:55
【问题描述】:
我遇到了 mypy 抛出错误说我缺少返回语句的问题。虽然我在函数中有一个,但它仍然存在。我做错了吗?
(我用的是python3.8)
def misc_menu_choice(misc_menu_input: str) -> str:
"""Provides mapping for the misc_menu"""
try:
if misc_menu_input == '1':
list_all()
if misc_menu_input == '2':
intermarriages()
elif misc_menu_input == '3':
toggle_program()
toggle_living_only()
elif misc_menu_input == '4':
selection = get_user_input(main_menu())
main_menu_selection(selection)
elif misc_menu_input == '':
print(f'Current ID: {current_person}\t\t\
Living Only: {program_status}')
miscellanious_menu_prompt()
else:
print('Please select again')
miscellanious_menu_prompt()
return misc_menu_input
except ValueError:
print("That is not an option")
miscellanious_menu_prompt()
【问题讨论】:
-
捕获异常后不会返回任何内容。
标签: python python-3.x type-hinting mypy python-typing