Skip to content

Commit ae895a3

Browse files
committed
Add default functions to save user typing
1 parent e1358b6 commit ae895a3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

stringtopy/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def str_to_float_converter(use_none_on_fail=False):
2424
Returns a human friendly float converter, can use use_none_on_fail to
2525
return None if value cannot be converted.
2626
"""
27-
def str_to_float(s):
27+
def str_to_float_func(s):
2828
"""
2929
Convert a string to a float
3030
"""
@@ -34,15 +34,15 @@ def str_to_float(s):
3434
if use_none_on_fail:
3535
return None
3636
raise
37-
return str_to_float
37+
return str_to_float_func
3838

3939

4040
def str_to_int_converter(use_none_on_fail=False):
4141
"""
4242
Returns a human friendly int converter, can use use_none_on_fail to return
4343
None if value cannot be converted.
4444
"""
45-
def str_to_int(s):
45+
def str_to_int_func(s):
4646
"""
4747
Convert a string to a int
4848
"""
@@ -55,7 +55,7 @@ def str_to_int(s):
5555
if use_none_on_fail:
5656
return None
5757
raise
58-
return str_to_int
58+
return str_to_int_func
5959

6060

6161
def str_to_bool_converter(
@@ -90,7 +90,7 @@ def str_to_bool_converter(
9090
"{} are both True and False".format(boolean_true & boolean_false)
9191
)
9292

93-
def str_to_bool(s):
93+
def str_to_bool_func(s):
9494
"""
9595
Convert a string to a bool, based on settings
9696
"""
@@ -100,4 +100,11 @@ def str_to_bool(s):
100100
if s in boolean_false:
101101
return False
102102
raise ValueError("{} is neither True nor False.".format(s))
103-
return str_to_bool
103+
return str_to_bool_func
104+
105+
106+
# versions using defaults so that users can import the actual functions, rather
107+
# than creating their own
108+
str_to_float = str_to_float_converter()
109+
str_to_int = str_to_int_converter()
110+
str_to_bool = str_to_bool_converter()

0 commit comments

Comments
 (0)