Skip to content

Commit

Permalink
Simplified material append.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Nov 26, 2024
1 parent 224b08e commit 5287e0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions montepy/data_inputs/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,12 @@ def append(self, nuclide_frac_pair: tuple[Nuclide, float]):
self._check_valid_comp(nuclide_frac_pair)
self._elements.add(nuclide_frac_pair[0].element)
self._nuclei.add(nuclide_frac_pair[0].nucleus)
if not isinstance(nuclide_frac_pair[1], syntax_node.ValueNode):
node = self._generate_default_node(
float, str(nuclide_frac_pair[1]), "\n" + " " * DEFAULT_INDENT
)
syntax_node.ValueNode(str(nuclide_frac_pair[1]), float)
node.is_negatable_float = True
nuclide_frac_pair = (nuclide_frac_pair[0], node)
else:
node = nuclide_frac_pair[1]
node = self._generate_default_node(
float, str(nuclide_frac_pair[1]), "\n" + " " * DEFAULT_INDENT
)
syntax_node.ValueNode(str(nuclide_frac_pair[1]), float)
node.is_negatable_float = True
nuclide_frac_pair = (nuclide_frac_pair[0], node)
node.is_negative = not self._is_atom_fraction
self._components.append(nuclide_frac_pair)
self._tree["data"].append_nuclide(("_", nuclide_frac_pair[0]._tree, node))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_material_deleter(_, big_material):
assert old_comp[0] not in big_material
old_comps = big_material[0:2]
del big_material[0:2]
for nuc, _ in old_comps:
for nuc, _f in old_comps:
assert nuc not in big_material
with pytest.raises(TypeError):
del big_material["hi"]
Expand Down

0 comments on commit 5287e0b

Please sign in to comment.