File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed
aws_lambda_powertools/shared Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 1
1
from distutils .util import strtobool
2
+ from typing import Any , Union
2
3
3
4
4
- def resolve_truthy_env_var_choice (env : str , choice : bool = None ) -> bool :
5
+ def resolve_truthy_env_var_choice (env : Any , choice : bool = None ) -> bool :
6
+ """ Pick explicit choice over truthy env value, if available, otherwise return truthy env value
7
+
8
+ NOTE: Environment variable should be resolved by the caller.
9
+
10
+ Parameters
11
+ ----------
12
+ env : Any
13
+ environment variable actual value
14
+ choice : bool
15
+ explicit choice
16
+
17
+ Returns
18
+ -------
19
+ choice : str
20
+ resolved choice as either bool or environment value
21
+ """
5
22
return choice if choice is not None else strtobool (env )
6
23
7
24
8
- def resolve_env_var_choice (env : str , choice : bool = None ) -> bool :
25
+ def resolve_env_var_choice (env : Any , choice : bool = None ) -> Union [bool , Any ]:
26
+ """ Pick explicit choice over env, if available, otherwise return env value received
27
+
28
+ NOTE: Environment variable should be resolved by the caller.
29
+
30
+ Parameters
31
+ ----------
32
+ env : Any
33
+ environment variable actual value
34
+ choice : bool
35
+ explicit choice
36
+
37
+ Returns
38
+ -------
39
+ choice : str
40
+ resolved choice as either bool or environment value
41
+ """
9
42
return choice if choice is not None else env
Original file line number Diff line number Diff line change 1
- from aws_lambda_powertools .shared .functions import resolve_truthy_env_var_choice
1
+ from aws_lambda_powertools .shared .functions import resolve_env_var_choice , resolve_truthy_env_var_choice
2
2
3
3
4
4
def test_resolve_env_var_choice_explicit_wins_over_env_var ():
5
5
assert resolve_truthy_env_var_choice (env = "true" , choice = False ) is False
6
+ assert resolve_env_var_choice (env = "something" , choice = False ) is False
6
7
7
8
8
9
def test_resolve_env_var_choice_env_wins_over_absent_explicit ():
9
10
assert resolve_truthy_env_var_choice (env = "true" ) == 1
11
+ assert resolve_env_var_choice (env = "something" ) == "something"
You can’t perform that action at this time.
0 commit comments