From bd3c76a66cab9582b363c8ff1ec5a103e734702f Mon Sep 17 00:00:00 2001 From: beckydvn <18rldv@queensu.ca> Date: Thu, 3 Aug 2023 16:48:55 -0400 Subject: [PATCH] fix linting --- .../parsers/json_config_parser.py | 14 ++++++------ .../for_generating/parsers/parse_for_rasa.py | 2 +- .../for_generating/parsers/pddl_parser.py | 22 +++++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/plan4dial/for_generating/parsers/json_config_parser.py b/plan4dial/for_generating/parsers/json_config_parser.py index ce3c639..fddb151 100644 --- a/plan4dial/for_generating/parsers/json_config_parser.py +++ b/plan4dial/for_generating/parsers/json_config_parser.py @@ -83,7 +83,7 @@ def configure_assignments(known: Union[bool, str]) -> str: str: The Hovor assignment equivalent to the "known" parameter provided. """ return ( - ("found" if known else "didnt-find") if type(known) == bool else "maybe-found" + ("found" if known else "didnt-find") if type(known) is bool else "maybe-found" ) @@ -98,7 +98,7 @@ def _configure_certainty(known: Union[bool, str]) -> str: Returns: str: The Hovor certainty equivalent to the "known" parameter provided. """ - return ("Known" if known else "Unknown") if type(known) == bool else "Uncertain" + return ("Known" if known else "Unknown") if type(known) is bool else "Uncertain" @config(auto_simplify=True) @@ -117,7 +117,7 @@ def _convert_to_formula(condition: Dict) -> Union[And, Or]: formula_terms = [] # if we get passed a list, update formula_terms by the conversion of each element # in the list - if type(condition) == list: + if type(condition) is list: formula_terms.extend( [ formula @@ -188,7 +188,7 @@ def _configure_value_setter(loaded_yaml: Dict, ctx_var: str) -> None: # possible values the context variable can be set to var_options = ( list(ctx_var_cfg["options"].keys()) - if type(ctx_var_cfg["options"]) == dict + if type(ctx_var_cfg["options"]) is dict else ctx_var_cfg["options"] ) # create flag context variables that represent the given ctx_var being set to all @@ -541,7 +541,7 @@ def _add_value_setters(loaded_yaml: Dict) -> None: for cond, cond_cfg in act_cfg["condition"].items(): if "value" in cond_cfg: option = cond_cfg["value"] - if type(option) == str: + if type(option) is str: if option not in loaded_yaml["context_variables"][cond]["options"]: raise AssertionError( f'Cannot specify the value "{option}" for the context \ @@ -639,7 +639,7 @@ def _convert_actions(loaded_yaml: Dict) -> None: if cond_config_key == "known": json_config_cond.append( ([cond, "Known"] if cond_config_val else [cond, "Unknown"]) - if type(cond_config_val) == bool + if type(cond_config_val) is bool else [cond, "Uncertain"] ) elif cond_config_key == "value": @@ -697,7 +697,7 @@ def _convert_actions(loaded_yaml: Dict) -> None: processed[act]["intents"] = {} for intent in intents: # don't consider null intents - if type(intent) == str: + if type(intent) is str: if intent in loaded_yaml["intents"]: processed[act]["intents"][intent] = loaded_yaml["intents"][ intent diff --git a/plan4dial/for_generating/parsers/parse_for_rasa.py b/plan4dial/for_generating/parsers/parse_for_rasa.py index 3639c65..eab01b8 100644 --- a/plan4dial/for_generating/parsers/parse_for_rasa.py +++ b/plan4dial/for_generating/parsers/parse_for_rasa.py @@ -70,7 +70,7 @@ def make_nlu_file(loaded_yaml: Dict) -> Dict: ] # if the options have variations, make intent examples of the # variations, using the original option as the true val - if type(ctx_var["options"]) == dict: + if type(ctx_var["options"]) is dict: for option, option_var in ctx_var["options"].items(): variations[variable].extend( _create_intent_example(v, variable, true_value=option) diff --git a/plan4dial/for_generating/parsers/pddl_parser.py b/plan4dial/for_generating/parsers/pddl_parser.py index d524002..6e11d7b 100644 --- a/plan4dial/for_generating/parsers/pddl_parser.py +++ b/plan4dial/for_generating/parsers/pddl_parser.py @@ -46,7 +46,7 @@ def _return_flag_value_fluent( str: The fluent version of a flag or fflag context variable depending on the setting supplied. """ - if type(value) == bool: + if type(value) is bool: return f"({v_name})" if value else f"(not ({v_name}))" elif is_fflag: return f"(maybe__{v_name})" @@ -74,7 +74,7 @@ def _return_certainty_fluents(v_name: str, is_fflag: bool, certainty: str) -> Li elif certainty == "Uncertain": known = "maybe" - if type(known) == bool: + if type(known) is bool: # only include "maybe"s if the known type is fflag return ( ( @@ -169,7 +169,7 @@ def get_precond_fluents( cond_key_fflag = _get_is_fflag(context_variables, cond_key) # update precond depending on the type of condition value if cond_val is not None: - if type(cond_val) == bool: + if type(cond_val) is bool: precond.add( _return_flag_value_fluent(cond_key, cond_key_fflag, cond_val) ) @@ -237,8 +237,10 @@ def _action_to_pddl(context_variables: Dict, act: str, act_config: Dict) -> str: outer_brackets=False, ) # convert the effects - effects = f"\n{TAB * 2}:effect\n{TAB * 3}(labeled-oneof " + \ - act_config['effect']['global-outcome-name'] + effects = ( + f"\n{TAB * 2}:effect\n{TAB * 3}(labeled-oneof " + + act_config["effect"]["global-outcome-name"] + ) # iterate through all the outcomes for out_config in act_config["effect"]["outcomes"]: if "updates" in out_config: @@ -294,7 +296,7 @@ def get_init_fluents(context_variables: Dict) -> Tuple[Set[str], Set[str]]: # if this variable has a known setting if "known" in var_config: known_status = var_config["known"]["init"] - if type(known_status) == bool: + if type(known_status) is bool: # if known is True, add this to the partial satate if known_status: init_true.add(f"(know__{var})") @@ -309,7 +311,7 @@ def get_init_fluents(context_variables: Dict) -> Tuple[Set[str], Set[str]]: # similarly add the context variables that are flag/fflag types if var_config["type"] in ["flag", "fflag"]: status = var_config["config"] - if type(status) == bool: + if type(status) is bool: if status: init_true.add(f"({var})") else: @@ -362,8 +364,10 @@ def parse_to_pddl(loaded_yaml: Dict) -> Tuple[str, str]: name_wrap=":predicates", ) actions = _actions_to_pddl(loaded_yaml) - domain = f"(define\n{TAB}(domain {loaded_yaml['name']})\n{TAB}(:requirements " + \ - f":strips)\n{TAB}(:types )\n{TAB}(:constants ){predicates}\n{actions}\n)" + domain = ( + f"(define\n{TAB}(domain {loaded_yaml['name']})\n{TAB}(:requirements " + + f":strips)\n{TAB}(:types )\n{TAB}(:constants ){predicates}\n{actions}\n)" + ) problem_def = f"(define\n{TAB}(problem {loaded_yaml['name']}-problem)\n{TAB} \ (:domain {loaded_yaml['name']})\n{TAB}(:objects )" init = _fluents_to_pddl(