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:
GuySten 2026-01-28 10:02:02 +02:00 committed by GitHub
parent db426b66ca
commit 008d584607
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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