11 yaml loader and factory cycle detection reporting#18
Conversation
|
The detection works, however I would expect a more comprehensive error, such as: I modified tests/config/sr/magnet_models/QF1AC01.yaml and for the curve field, i put: |
|
I propose the following patch which produces the error: Still need to implemented access to line number mapping... def __init__(self, filename:str, parent_path_stack:list):
self.path:Path = get_root_folder() / filename
self.files_stack = parent_path_stack if parent_path_stack is not None else []
self.files_stack.append(self.path)
# Expand condition
def hasToExpand(self,value):
expand = isinstance(value,str) and any(value.endswith(suffix) for suffix in accepted_suffixes)
if expand:
expandedPath:Path = get_root_folder() / value
if any(expandedPath.samefile(p) for p in self.files_stack):
raise PyAMLException(f"{self.path}: Circular inclusion: {value}")
return expand
# Recursively expand a dict
def expand_dict(self,d:dict):
for key, value in d.items():
if self.hasToExpand(value):
d[key] = load(value, self.files_stack)
else:
self.expand(value) |
|
@JeanLucPons, have another look, I have updated tests and set a better exception message. |
|
Thanks it is much better, however, same problem with list. |
|
Note: no reviewer is assigned to this pull request. |
No description provided.