Redid 3 days of work after deleting it

class_based_refactor
Nicholas Hope 2022-08-25 21:28:43 -04:00
parent 1fbe47943b
commit eef096777e
1 changed files with 10 additions and 17 deletions

View File

@ -10,21 +10,8 @@ def verifyConfig(cfg: dict) -> (dict, dict):
defaults = []
if 'default' in cfg:
defaultCFG = cfg.pop('default')
errMessages = []
for key, data in defaultCFG.items():
bind = tftypes.bind(key, data)
if bind.targetType is not None:
bind = bind.targetType(bind.key, bind.fields)
defaults.append(bind)
errMessages.extend(bind.errors)
if len(errMessages) > 0:
errors.update({'default': errMessages})
classList = [
'default',
'scout',
'soldier',
'pyro',
@ -36,10 +23,12 @@ def verifyConfig(cfg: dict) -> (dict, dict):
'spy'
]
for cclass in classList:
for isclass, cclass in enumerate(classList):
classCFG = None
classBinds = []
className = cclass
if isinstance(cclass, str) and cclass in cfg:
classCFG = cfg.pop(cclass)
elif isinstance(cclass, tuple):
@ -53,18 +42,22 @@ def verifyConfig(cfg: dict) -> (dict, dict):
# It may be less efficient this way, but
# it makes for more descriptive error messages
continue
errMessages = []
for key, data in classCFG.items():
bind = tftypes.bind(key, data)
if bind.targetType is not None:
bind = bind.targetType(bind.key, bind.fields)
bind = bind.toTargetType()
if isclass:
classBinds.append(bind)
else:
defaults.append(bind)
errMessages.extend(bind.errors)
if len(errMessages) > 0:
errors.update( {className: errMessages} )
verifiedConfig.update({className: classBinds})
# Turn list into only strings by expanding tuples