Skip to content

Commit 8e0cbc8

Browse files
committed
python lint
1 parent 9e30581 commit 8e0cbc8

3 files changed

Lines changed: 19 additions & 33 deletions

File tree

openc3/python/openc3/api/api_shared.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,6 @@ def _check_eval(target_name, packet_name, item_name, comparison_to_eval, value):
970970

971971
try:
972972
eval_is_valid = _check_eval_validity(value, comparison_to_eval)
973-
# if not eval_is_valid:
974-
# raise CheckError("ERROR: Invalid comparison for types")
975973
if eval_is_valid and eval(string):
976974
print(f"{check_str} success {with_value}")
977975
else:
@@ -1006,15 +1004,15 @@ def _check_eval_validity(value, comparison):
10061004
# It will raise an appropriate error (like NameError for undefined constants)
10071005
return True
10081006

1009-
if operator in [">=", "<=", ">", "<"]:
1010-
if value is None or operand is None or isinstance(value, list) or isinstance(operand, list):
1011-
return False
1007+
if operator in [">=", "<=", ">", "<"] and (
1008+
value is None or operand is None or isinstance(value, list) or isinstance(operand, list)
1009+
):
1010+
return False
10121011

1013-
if operator == "in": # Ruby doesn't have this operator
1014-
if isinstance(operand, str) and not isinstance(value, str) or not isinstance(operand, list):
1015-
return False
1016-
1017-
return True
1012+
# Ruby doesn't have the "in" operator
1013+
return not (
1014+
operator == "in" and (isinstance(operand, str) and not isinstance(value, str) or not isinstance(operand, list))
1015+
)
10181016

10191017

10201018
# Interesting formatter to a specific number of significant digits:

openc3/python/openc3/script/api_shared.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,27 +1091,15 @@ def _check_eval_validity(value, comparison):
10911091
# It will raise an appropriate error (like NameError for undefined constants)
10921092
return True
10931093

1094-
if operator in [">=", "<=", ">", "<"]:
1095-
if value is None or operand is None or isinstance(value, list) or isinstance(operand, list):
1096-
return False
1097-
1098-
if operator == "in": # Ruby doesn't have this operator
1099-
if isinstance(operand, str) and not isinstance(value, str) or not isinstance(operand, list):
1100-
return False
1101-
1102-
return True
1103-
1104-
operator, operand = extract_operator_and_operand_from_comparison(comparison)
1105-
1106-
if operator in [">=", "<=", ">", "<"]:
1107-
if value is None or operand is None or isinstance(value, list) or isinstance(operand, list):
1108-
return False
1109-
1110-
if operator == "in": # Ruby doesn't have this operator
1111-
if isinstance(operand, str) and not isinstance(value, str) or not isinstance(operand, list):
1112-
return False
1113-
1114-
return True
1094+
if operator in [">=", "<=", ">", "<"] and (
1095+
value is None or operand is None or isinstance(value, list) or isinstance(operand, list)
1096+
):
1097+
return False
1098+
1099+
# Ruby doesn't have the "in" operator
1100+
return not (
1101+
operator == "in" and (isinstance(operand, str) and not isinstance(value, str) or not isinstance(operand, list))
1102+
)
11151103

11161104

11171105
# Interesting formatter to a specific number of significant digits:

openc3/python/openc3/utilities/extract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,6 @@ def extract_operator_and_operand_from_comparison(comparison):
273273
else:
274274
try:
275275
operand = json.loads(operand)
276-
except json.JSONDecodeError:
277-
raise RuntimeError(f"ERROR: Unable to parse operand: {operand}")
276+
except json.JSONDecodeError as err:
277+
raise RuntimeError(f"ERROR: Unable to parse operand: {operand}") from err
278278
return operator, operand

0 commit comments

Comments
 (0)