Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(
step=1,
data=None,
convergence_check=True,
post_func_skip_list=None,
**kwargs,
):
"""Constructor.
Expand Down Expand Up @@ -163,6 +164,8 @@ def __init__(
The raw data of System class.
convergence_check : boolean
Whether to request a convergence check.
post_func_skip_list : list of str
The list of post function names to skip.
**kwargs : dict
other parameters
"""
Expand All @@ -180,6 +183,9 @@ def __init__(
return
if file_name is None:
return
self.post_func_skip_list = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Initialize the skip list before either early return

System() returns at file_name is None without defining post_func_skip_list. A later System().from_fmt(...) reaches the post-function branch and raises AttributeError, which I reproduced on this head. Move this initialization above both the data and file_name early-return blocks, and add a chained empty-constructor loading regression test. A complete GitHub suggestion cannot be attached to only these added lines because the fix must move them above unchanged context.

post_func_skip_list if post_func_skip_list is not None else []
)
self.from_fmt(
file_name,
fmt,
Expand Down Expand Up @@ -229,7 +235,12 @@ def from_fmt_obj(self, fmtobj, file_name, **kwargs):
self.data = {**self.data, **data}
self.check_data()
if hasattr(fmtobj.from_system, "post_func"):
assert isinstance(
self.post_func_skip_list, list
), "post_func_skip_list should be a list of string"
for post_f in fmtobj.from_system.post_func:
if post_f in self.post_func_skip_list:
continue
self.post_funcs.get_plugin(post_f)(self)
return self

Expand Down