mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
Warn users when setting undefined attributes in ``openmc.Settings`` (#3746)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
db426b66ca
commit
008d584607
1 changed files with 12 additions and 1 deletions
|
|
@ -4,13 +4,14 @@ import itertools
|
|||
from math import ceil
|
||||
from numbers import Integral, Real
|
||||
from pathlib import Path
|
||||
import traceback
|
||||
|
||||
import lxml.etree as ET
|
||||
import warnings
|
||||
import openmc
|
||||
import openmc.checkvalue as cv
|
||||
from openmc.checkvalue import PathLike
|
||||
from openmc.stats.multivariate import MeshSpatial, Box, PolarAzimuthal, Isotropic
|
||||
from openmc.stats.multivariate import MeshSpatial
|
||||
from ._xml import clean_indentation, get_elem_list, get_text
|
||||
from .mesh import _read_meshes, RegularMesh, MeshBase
|
||||
from .source import SourceBase, MeshSource, IndependentSource
|
||||
|
|
@ -467,6 +468,16 @@ class Settings:
|
|||
for key, value in kwargs.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
def __setattr__(self, name: str, value):
|
||||
if not name.startswith('_'):
|
||||
try:
|
||||
getattr(self, name)
|
||||
except AttributeError as e:
|
||||
msg, = traceback.format_exception_only(e)
|
||||
msg = msg.strip().split(maxsplit=1)[-1]
|
||||
warnings.warn(msg, stacklevel=2)
|
||||
super().__setattr__(name, value)
|
||||
|
||||
@property
|
||||
def run_mode(self) -> str:
|
||||
return self._run_mode.value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue