def validate_parent_name(title): """Need a special fn for this because classes are auto coerced to uppercase by default.""" if is_identifier(title): if corrected := case_check(title, item_type="class"): return corrected else: return title
def test_case_check(self, input): """case_check(item, item_type="class", preferences="ask") """ # case 1- leave preference as 'ask'- will take y from builtins.input # and return a case corrected class identifier self.assertEqual(case_check("example"), "Example") # change item_type to field and preferences to corece- # automatically convert the item to lowercase and add underscrores. self.assertEqual( case_check("GOAT BISCUIT", item_type="field", preferences="coerce"), "goat_biscuit") # preference is none so the item is returned with no side-effects self.assertEqual(case_check("butter", preferences="none"), "butter")
def validate_members(items, item_type="class"): """does basic validation for a standard inlines' members 1. ensure each item is identifier 2. ensure it has appropriate case items [list | str] : class name or attributes/methods to validate. item_type="class" [str] : which type of identifier to validate- class or field. returns: """ # this ibnky= if item_type == "class": return class_correct_convention(items) elif item_type in ("attribute", "method"): # This is a lil weird. item_type = "field" container = [] for item in items: item = item.strip() if is_identifier(item): container.append(case_check(item, item_type=item_type)) if len(container): return container return None
def attributes_main(attr: list): """ overseer fn for ensuring validity of each attr. Args: attr ([type]): [description] """ # y is the actual value for x, y in enumerate(attr): if is_identifier(y): # heres where you would override the default # arg if you wanted to coerce the case if returned := case_check(y, item_type="field"): attr[x] = returned # dont think we need an else block because ^^ always return truthy else: response = input(f"the attribute {y} is not a valid identifier\n\ delete {y} from attribute set {attr} (y/n)?") if response in ("y", "yes"): del attr[x]
def validate_module_name(title): if is_identifier(title): if corrected := case_check(title, item_type="module"): return corrected else: return title