xoutil.symbols – Logical values

Special logical values like Unset, Undefined, Ignored, Invalid, …

All values only could be True or False but are intended in places where None is expected to be a valid value or for special Boolean formats.

xoutil.symbols.Ignored = Ignored

To be used in arguments that are currently ignored because they are being deprecated. The only valid reason to use Ignored is to signal ignored arguments in method’s/function’s signature

xoutil.symbols.Invalid = Invalid

To be used in functions resulting in a fail where False could be a valid value.

class xoutil.symbols.MetaSymbol[source]

Meta-class for symbol types.

nameof(s)[source]

Get the name of a symbol instance (s).

parse(name)[source]

Returns instance from a string.

Standard Python Boolean values are parsed too.

xoutil.symbols.This = This

To be used as a mark for current context as a mechanism of comfort.

xoutil.symbols.Undefined = Undefined

False value for local scope use or where Unset could be a valid value

xoutil.symbols.Unset = Unset

False value, mainly for function parameter definitions, where None could be a valid value.

class xoutil.symbols.boolean(*args, **kwds)[source]

Instances are custom logical values (True or False).

Special symbols allowing only logical (False or True) values.

For example:

>>> true = boolean('true', True)
>>> false = boolean('false')
>>> none = boolean('false')
>>> unset = boolean('unset')

>>> class X(object):
...      attr = None

>>> getattr(X(), 'attr') is not None
False

>>> getattr(X(), 'attr', false) is not false
True

>>> none is false
True

>>> false == False
True

>>> false == unset
True

>>> false is unset
False

>>> true == True
True
class xoutil.symbols.symbol(*args, **kwds)[source]

Instances are custom symbols.

Symbol instances identify uniquely a semantic concept by its name. Each one has an ordinal value associated.

For example:

>>> ONE2MANY = symbol('ONE2MANY')
>>> ONE_TO_MANY = symbol('ONE2MANY')

>>> ONE_TO_MANY is ONE2MANY
True