@@ -33,8 +33,8 @@ def __init__(
3333 self ._mutable = mutable
3434 self ._validator = validator
3535 if name in os .environ :
36- self ._value = validator (os .environ [name ])
37- logger .debug (f"{ self ._name } ={ self .get () } " )
36+ self ._current = validator (os .environ [name ])
37+ logger .debug (f"{ self ._name } ={ self .current } " )
3838 ALL_OPTIONS .add (self )
3939
4040 @property
@@ -52,39 +52,44 @@ def default(self) -> _O:
5252 """This option's default value"""
5353 return self ._default
5454
55+ @property
56+ def current (self ) -> _O :
57+ try :
58+ return self ._current
59+ except AttributeError :
60+ return self ._default
61+
62+ @current .setter
63+ def current (self , new : _O ) -> None :
64+ self .set_current (new )
65+ return None
66+
5567 def is_set (self ) -> bool :
5668 """Whether this option has a value other than its default."""
57- return hasattr (self , "_value" )
58-
59- def get (self ) -> _O :
60- """Get the current value of this option."""
61- return cast (_O , getattr (self , "_value" , self ._default ))
69+ return hasattr (self , "_current" )
6270
63- def set (self , new : Any ) -> None :
71+ def set_current (self , new : Any ) -> None :
6472 """Set the value of this option
6573
6674 Raises a ``TypeError`` if this option is not :attr:`Option.mutable`.
6775 """
6876 if not self ._mutable :
6977 raise TypeError (f"{ self } cannot be modified after initial load" )
70- self ._value = self ._validator (new )
71- logger .debug (f"{ self ._name } ={ self ._value } " )
78+ self ._current = self ._validator (new )
79+ logger .debug (f"{ self ._name } ={ self ._current } " )
7280
7381 def set_default (self , new : _O ) -> _O :
7482 """Set the value of this option if not :meth:`Option.is_set`
7583
7684 Returns the current value (a la :meth:`dict.set_default`)
7785 """
78- if not hasattr (self , "_value " ):
79- self .set (new )
80- return self ._value
86+ if not hasattr (self , "_current " ):
87+ self .set_current (new )
88+ return self ._current
8189
8290 def reload (self ) -> None :
83- """Reload this option from its environment variable
84-
85- Returns the old value of the option.
86- """
87- self .set (os .environ .get (self ._name , self ._default ))
91+ """Reload this option from its environment variable"""
92+ self .set_current (os .environ .get (self ._name , self ._default ))
8893
8994 def reset (self ) -> None :
9095 """Reset the value of this option to its default setting
@@ -93,7 +98,7 @@ def reset(self) -> None:
9398 """
9499 if not self ._mutable :
95100 raise TypeError (f"{ self } cannot be modified after initial load" )
96- delattr (self , "_value " )
101+ delattr (self , "_current " )
97102
98103 def __repr__ (self ) -> str :
99- return f"Option({ self ._name } ={ self .get () !r} )"
104+ return f"Option({ self ._name } ={ self .current !r} )"
0 commit comments