Module xsentinels.sentinel
Classes
class Sentinel (*args, **kwargs)
-
Expand source code
class Sentinel(Singleton): pass
This can be used as the superclass that should always be a Singleton no mater what. Example of something you may want to make a true singleton is a sentinel-type, like the
NoneType
that Python has.See the
default-type.Default
for an example of how you can use this, or the following code example:class DefaultType(Singleton): pass Default = DefaultType()
Class Arguments:
-
name: You can provide a name for instances of the type, this is what they will return from
__repr__
for the object's description.By default, if you don't provide this we take the class name, and strip off the word
"Type"
and the end of class name (if present at end of class name). Whatever is left is what we return for by default for thisname
argument. -
value_as_bool: Default's to
True
. The value provided here is what is returned from__bool__
. This is what Python uses as the bool value for the object. Consider overriding this to False if you want to make a sentential type-objects.It seems like sentential type-objects normally want to be False like.
Similar to why
None
has False as it's bool-value.You can override by setting
value_as_bool=True
as a class argument, ie:```python from xsentinels import Singleton
class MySingletonType(Singleton, value_as_bool=True) pass
Will now be
True
like when used as a bool.assert MySingletonType()
```
Ancestors
Subclasses
-