Fix "KeyError: 'No'" for "No" values
jingzhaoou opened this issue · comments
It is better to change the line at
ssh_config/ssh_config/keywords.py
Line 19 in be893bc
to the following. Otherwise, "No" values would run into KeyError: 'No'
errors.
convert[value.lower()]
I suggest the code to look like
def yes_or_no(value: str) -> bool:
"""Convert 'yes' or 'no' to True or False
Args:
value (str): The string containing 'yes' or 'no'
Returns:
bool: True if value is 'yes', False if value is 'no'
"""
if value is None:
return
if value.lower() not in ('yes', 'no', 'true', 'false'):
raise TypeError(f"Yes or No is required: {value}")
convert = {
"yes": True,
"no": False,
"true": True,
"false": False,
True: "yes",
False: "no",
}
return convert[value.lower()]
Otherwise, I would run into errors when reading back the updated config file.