added missing return call in new id generation funcs

This commit is contained in:
PatchOfScotland
2023-02-10 15:33:01 +01:00
parent 7059a7340d
commit b8885146fa
3 changed files with 19 additions and 7 deletions

View File

@ -178,10 +178,10 @@ def valid_dict(variable:Dict[Any, Any], key_type:Type, value_type:Type,
f"in dict '{variable}'") f"in dict '{variable}'")
def valid_list(variable:List[Any], entry_type:Type, def valid_list(variable:List[Any], entry_type:Type,
alt_types:List[Type]=[], min_length:int=1)->None: alt_types:List[Type]=[], min_length:int=1, hint:str="")->None:
"""Checks that a given list is valid. Value types are checked and a """Checks that a given list is valid. Value types are checked and a
ValueError or TypeError is raised if a problem is encountered.""" ValueError or TypeError is raised if a problem is encountered."""
check_type(variable, List) check_type(variable, List, hint=hint)
# Check length meets minimum # Check length meets minimum
if len(variable) < min_length: if len(variable) < min_length:
@ -189,8 +189,12 @@ def valid_list(variable:List[Any], entry_type:Type,
f"of length {min_length}") f"of length {min_length}")
# Check type of each value # Check type of each value
for entry in variable: for n, entry in enumerate(variable):
check_type(entry, entry_type, alt_types=alt_types) if hint:
check_type(entry, entry_type, alt_types=alt_types,
hint=f"{hint}[{n}]")
else:
check_type(entry, entry_type, alt_types=alt_types)
def valid_path(variable:str, allow_base:bool=False, extension:str="", def valid_path(variable:str, allow_base:bool=False, extension:str="",
min_length:int=1): min_length:int=1):

View File

@ -507,7 +507,9 @@ def create_rule(pattern:BasePattern, recipe:BaseRecipe,
through the 'new_rules' variable.""" through the 'new_rules' variable."""
check_type(pattern, BasePattern, hint="create_rule.pattern") check_type(pattern, BasePattern, hint="create_rule.pattern")
check_type(recipe, BaseRecipe, hint="create_rule.recipe") check_type(recipe, BaseRecipe, hint="create_rule.recipe")
valid_list(new_rules, BaseRule, min_length=0) valid_list(new_rules, BaseRule, min_length=0, hint="create_rule.new_rules")
print("passed initial check")
# Imported here to avoid circular imports at top of file # Imported here to avoid circular imports at top of file
import rules import rules
@ -516,18 +518,24 @@ def create_rule(pattern:BasePattern, recipe:BaseRecipe,
for r in inspect.getmembers(sys.modules["rules"], inspect.isclass) \ for r in inspect.getmembers(sys.modules["rules"], inspect.isclass) \
if (issubclass(r[1], BaseRule))]} if (issubclass(r[1], BaseRule))]}
print("got base rules")
# Add in new rules # Add in new rules
for rule in new_rules: for rule in new_rules:
all_rules[(rule.pattern_type, rule.recipe_type)] = rule all_rules[(rule.pattern_type, rule.recipe_type)] = rule
print("got new rules")
# Find appropriate rule type from pattern and recipe types # Find appropriate rule type from pattern and recipe types
key = (type(pattern).__name__, type(recipe).__name__) key = (type(pattern).__name__, type(recipe).__name__)
print("got key")
if (key) in all_rules: if (key) in all_rules:
return all_rules[key]( return all_rules[key](
generate_rule_id(), generate_rule_id(),
pattern, pattern,
recipe recipe
) )
print("no key")
# Raise error if not valid rule type can be found # Raise error if not valid rule type can be found
raise TypeError(f"No valid rule for Pattern '{pattern}' and Recipe " raise TypeError(f"No valid rule for Pattern '{pattern}' and Recipe "
f"'{recipe}' could be found.") f"'{recipe}' could be found.")

View File

@ -23,7 +23,7 @@ def _generate_id(prefix:str="", length:int=16, existing_ids:List[str]=[],
f"using values '{charset}' and length of '{length}'.") f"using values '{charset}' and length of '{length}'.")
def generate_rule_id(): def generate_rule_id():
_generate_id(prefix="rule_") return _generate_id(prefix="rule_")
def generate_job_id(): def generate_job_id():
_generate_id(prefix="job_") return _generate_id(prefix="job_")