Option¶
Note
Usage on each methods are valid on the premise that the following classes is defined in advance.
# coding: utf-8
from owlmixin import OwlMixin, TOption
from owlmixin.owlcollections import TDict, TList
from owlmixin.owlenum import OwlEnum, OwlObjectEnum
class Animal(OwlObjectEnum): # pragma: no cover
DOG = ("dog", {"cry": "bow-wow"})
CAT = ("cat", {"cry": "mewing"})
def cry(self):
return self.object["cry"]
class Color(OwlEnum): # pragma: no cover
RED = "red"
GREEN = "green"
BLUE = "blue"
class Food(OwlMixin): # pragma: no cover
name: str
names_by_lang: TOption[TDict[str]]
class Human(OwlMixin): # pragma: no cover
id: int
name: str
favorites: TList[Food]
class Machine(OwlMixin): # pragma: no cover
id: int
name: str
class Japanese(OwlMixin): # pragma: no cover
name: str
language: str = "japanese"
TOption¶
- class owlmixin.owloption.TOption(value)[source]¶
-
- get_or(default: T) T [source]¶
Usage:
>>> TOption(3).get_or(999) 3 >>> TOption(0).get_or(999) 0 >>> TOption(None).get_or(999) 999
- is_none() bool [source]¶
Usage:
>>> TOption(3).is_none() False >>> TOption(0).is_none() False >>> TOption(None).is_none() True
- any() bool [source]¶
Usage:
>>> TOption(3).any() True >>> TOption(0).any() True >>> TOption(None).any() False