Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dict.setdefault instead of if key not in dict: dict[key] = ... #452

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

janosh
Copy link
Member

@janosh janosh commented Jul 27, 2023

There are a bunch more cases like

if "parse_dos" not in self.task_document_kwargs:
    # parse DOS only for uniform band structure
    self.task_document_kwargs["parse_dos"] = mode == "uniform"

if "parse_bandstructure" not in self.task_document_kwargs:
    self.task_document_kwargs["parse_bandstructure"] = mode

# copy previous inputs
if "additional_cp2k_files" not in self.copy_cp2k_kwargs:
    self.copy_cp2k_kwargs["additional_cp2k_files"] = ("wfn",)

which can be simplified to

# parse DOS only for uniform band structure
self.task_document_kwargs.setdefault("parse_dos", mode == "uniform")
self.task_document_kwargs.setdefault("parse_bandstructure", mode)
# copy previous inputs
self.copy_cp2k_kwargs.setdefault("additional_cp2k_files", ("wfn",))

Might get to them later.

@janosh janosh changed the title Use dict.setdefault instead of if key not in dict: [dict[key] = ... Use dict.setdefault instead of if key not in dict: dict[key] = ... Jul 27, 2023
@janosh janosh changed the title Use dict.setdefault instead of if key not in dict: dict[key] = ... dict.setdefault instead of if key not in dict: dict[key] = ... Jul 28, 2023
@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #452 (9c1a9ff) into main (ff60708) will increase coverage by 0.22%.
Report is 8 commits behind head on main.
The diff coverage is 71.05%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #452      +/-   ##
==========================================
+ Coverage   65.08%   65.30%   +0.22%     
==========================================
  Files          74       74              
  Lines        7209     7186      -23     
  Branches      950      927      -23     
==========================================
+ Hits         4692     4693       +1     
+ Misses       2216     2208       -8     
+ Partials      301      285      -16     
Files Changed Coverage Δ
src/atomate2/amset/jobs.py 0.00% <0.00%> (ø)
src/atomate2/common/schemas/cclib.py 77.70% <0.00%> (ø)
src/atomate2/forcefields/schemas.py 94.28% <0.00%> (ø)
src/atomate2/vasp/run.py 40.98% <0.00%> (+0.66%) ⬆️
src/atomate2/vasp/sets/core.py 81.59% <0.00%> (ø)
src/atomate2/cp2k/jobs/core.py 84.72% <40.00%> (+4.45%) ⬆️
src/atomate2/vasp/sets/base.py 69.23% <66.66%> (ø)
src/atomate2/vasp/jobs/phonons.py 85.18% <83.33%> (+4.95%) ⬆️
src/atomate2/vasp/jobs/core.py 91.30% <90.00%> (+5.59%) ⬆️
src/atomate2/cp2k/jobs/base.py 93.33% <100.00%> (+4.80%) ⬆️
... and 3 more

@janosh janosh merged commit 95b15d5 into main Jul 28, 2023
8 checks passed
@janosh janosh deleted the use-dict-setdefault branch July 28, 2023 21:55
@utf utf added the house-keeping Formatting and code quality tweaks label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
house-keeping Formatting and code quality tweaks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants