Skip to content

Commit 75b5813

Browse files
GuyStenpaulromano
andauthored
Use cached property for openmc.data.Decay.sources (#3535)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent 14d51e0 commit 75b5813

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

openmc/data/decay.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections.abc import Iterable
2+
from functools import cached_property
23
from io import StringIO
34
from math import log
45
import re
@@ -339,7 +340,6 @@ def __init__(self, ev_or_filename):
339340
self.modes = []
340341
self.spectra = {}
341342
self.average_energies = {}
342-
self._sources = None
343343

344344
# Get head record
345345
items = get_head_record(file_obj)
@@ -506,14 +506,9 @@ def from_endf(cls, ev_or_filename):
506506
"""
507507
return cls(ev_or_filename)
508508

509-
@property
509+
@cached_property
510510
def sources(self):
511511
"""Radioactive decay source distributions"""
512-
# If property has been computed already, return it
513-
# TODO: Replace with functools.cached_property when support is Python 3.9+
514-
if self._sources is not None:
515-
return self._sources
516-
517512
sources = {}
518513
name = self.nuclide['name']
519514
decay_constant = self.decay_constant.n
@@ -571,8 +566,7 @@ def sources(self):
571566
merged_sources[particle_type] = combine_distributions(
572567
dist_list, [1.0]*len(dist_list))
573568

574-
self._sources = merged_sources
575-
return self._sources
569+
return merged_sources
576570

577571

578572
_DECAY_PHOTON_ENERGY = {}

0 commit comments

Comments
 (0)