Burgerlib Python
Loading...
Searching...
No Matches
burger.validators.BooleanProperty Class Reference

Class to enforce bool in member variable. More...

Inheritance diagram for burger.validators.BooleanProperty:
Collaboration diagram for burger.validators.BooleanProperty:

Public Member Functions

 __set__ (self, instance, value)
 Set the boolean value.
Public Member Functions inherited from burger.validators.Property
 __init__ (self, name)
 Initialize to default.
 __get__ (self, instance, owner=None)
 Return value.
 __set__ (self, instance, value)
 Set the string value.

Additional Inherited Members

Protected Attributes inherited from burger.validators.Property
 _name = name
 The real name of the class instance.

Detailed Description

Class to enforce bool in member variable.

See also
strutils.string_to_bool

Examples

"Inherit from (object) for Python 2.7"
>>> class foo(object):
"Init to false"
x = BooleanProperty(False)
"Init to true"
y = BooleanProperty(True)
"Init to None"
z = BooleanProperty()
"Create the class"
f = foo()
"Print True"
print(f.x)
"Print False"
f.x = False
print(f.x)
"f.x is set to bool False with string"
f.x = "False"
print(f.x)
"Exception on bad write"
f.x = "not boolean"
Traceback (most recent call last):
...
ValueError: Not boolean value

Member Function Documentation

◆ __set__()

burger.validators.BooleanProperty.__set__ ( self,
instance,
value )

Set the boolean value.

Parameters
instanceReference to object containing data
valueNone or value the can be converted to bool
Exception
ValueError on invalid input.
See also
strutils.string_to_bool