rename
Full documentation pages are generated for docstring
reference only and may contain symbols imported from other
modules. Imported symbols are not distinguished from locally
defined symbols and will appear in any module that they are
imported into. For better information on where symbols should
be imported from, review the sourcecode on the
github.
FoSpy.parsing.validators.rename
rename_dict
rename_dict(nameDict, cls)
Source code in FoSpy/parsing/validators/rename.py
| def rename_dict(nameDict, cls):
from FoSpy.blocks.blocks import SingleBlock
if not isinstance(nameDict, dict):
raise TypeError("The rename value must be a dictionary of key:value string pairs.")
vals = cls.build_validators()
outDict = nameDict.copy()
for name, rename in nameDict.items():
if name.startswith("_"):
outDict.pop(name)
continue
error = f"Cannot rename '{name}' to '{rename}' for '{cls.__name__}' block."
if name not in vals:
raise ValueError(error, f"'{name}' is not an expected key.")
if rename in vals:
raise ValueError(error, f"'{rename}' is already a registered key.")
return SingleBlock.dispatch_subclass(outDict)
|