hmf.core.domain.warn_once¶
- hmf.core.domain.warn_once(owner: object, key: str | tuple[str, ...], message: str, category: type[Warning] = <class 'hmf.exceptions.HMFExtrapolationWarning'>, *, stacklevel: int = 2) bool[source]¶
Emit a warning once per object and key.
The objects of
hmf.coreare frozen and compare by value, so this keeps the keys already warned about by the object’s identity, outside the object: two equal stages each warn once.- Parameters:
owner – The object the warning is about (e.g. a stage). If it can not be weakly referenced, the warning is emitted every time.
key – What the warning is about, e.g.
"k above the table". Each key warns once. A tuple of keys warns if any of them has not warned yet, and then counts as a warning about each (one message about several things).message – The warning’s message.
category – The warning’s class.
stacklevel – As for
warnings.warn(), from the caller of this function.
- Returns:
Whether the warning was emitted (False if it was already, for this object and key).
- Return type: