openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Python API: Replace magic strings with constants

Open tjlaboss opened this issue 3 years ago • 0 comments

Right now, the Python API has a lot of hardcoded strings in the code. For example, in summary.py:

if "dagmc" not in self._f['geometry'].attrs.keys():
. . .
for group in self._f['geometry/surfaces'].values():
. . .
for group in self._f['geometry/universes'].values():
. . .
for group in self._f['geometry/lattices'].values():
. . .

This could be replaced by:

"""tags.py:"""
GEOMETRY = "geometry"
SURFACE = GEOMETRY + "/surfaces"
. . .
"""summary.py"""
if "dagmc" in self._f[tags.GEOMETRY]:
. . .
for group in self._f[tags.SURFACE].values():
. . .

This makes it possible to change things in a single location instead of many, and creates tags accessible by users of the API.

If there's interest this is something I can do next time I'm bored.

tjlaboss avatar Feb 28 '22 17:02 tjlaboss