Sentinel

class PlasmaCalcs.tools.sentinels.Sentinel(name, repr=None, module_name=None, unique_includes_module=False)

Bases: object

Unique sentinel values. adapted from PEP 661.

name: str

str defining this sentinel. e.g. ‘UNSET’
repr: None or str
str defining repr for this sentinel. None –> use name.
module_name: None or str
name of module where this sentinel was defined. None –> infer it.
unique_includes_module: bool, default False
whether to include module name in “uniqueness” of this sentinel.
True –> calling Sentinel(name0) in module1 is a different object than Sentinel(name0) called in module2.
False –> Sentinel(name0) produces the same object regardless of where it was called from.
default False –> can access any sentinel value from any module, by providing its string.
e.g. Sentinel(‘UNSET’) is UNSET, always.
will crash if name is already associated to a Sentinel which is not an instance cls. Example:
class Subclass1(Sentinel): pass
class Subclass2(Sentinel): pass
A = Sentinel(‘SENTINEL_A’)
Subclass1(‘SENTINEL_A’) # crashes; A is not an instance of Subclass1.
A is Sentinel(‘SENTINEL_A’) # True, and no crash.
B = Subclass1(‘SENTINEL_B’)
B is Sentinel(‘SENTINEL_B’) # True; B is an instance of Sentinel, because Subclass1 is a subclass of Sentinel
Subclass2(‘SENTINEL_B’) # crashes; B is not an instance of Subclass2.

Methods

__new__(cls, name[, repr, module_name, ...])

return new Sentinel object.

static __new__(cls, name, repr=None, module_name=None, unique_includes_module=False)

return new Sentinel object.