Skip to content

Commit

Permalink
Do-not-return-error-codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiltingpenguin committed Oct 12, 2023
1 parent c714783 commit 373bc78
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions bindings/python3/econf/econf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,30 @@ def _ensure_valid_uint(val: int) -> int:

def set_value(
ef: EconfFile, group: str | bytes, key: str | bytes, value: Any
) -> Econf_err:
) -> None:
"""
Dynamically set a value in a keyfile and returns a status code
:param ef: EconfFile object to set value in
:param group: group of the key to be changed
:param key: key to be changed
:param value: desired value
:return: Error code
:return: Nothing
"""
if isinstance(value, int):
if value >= 0:
res = set_uint_value(ef, group, key, value)
set_uint_value(ef, group, key, value)
else:
res = set_int_value(ef, group, key, value)
set_int_value(ef, group, key, value)
elif isinstance(value, float):
res = set_float_value(ef, group, key, value)
set_float_value(ef, group, key, value)
elif isinstance(value, str) | isinstance(value, bytes):
res = set_string_value(ef, group, key, value)
set_string_value(ef, group, key, value)
elif isinstance(value, bool):
res = set_bool_value(ef, group, key, value)
set_bool_value(ef, group, key, value)
else:
raise TypeError(f"parameter {val} is not one of the supported types")
return res
return


def read_file(
Expand Down Expand Up @@ -317,19 +317,21 @@ def new_ini_file() -> EconfFile:
return result


def write_file(ef: EconfFile, save_to_dir: str, file_name: str) -> Econf_err:
def write_file(ef: EconfFile, save_to_dir: str, file_name: str) -> None:
"""
Write content of a keyfile to specified location
:param ef: Key-Value storage object
:param save_to_dir: directory into which the file has to be written
:param file_name: filename with suffix of the to be written file
:return: Error code
:return: Nothing
"""
c_save_to_dir = _encode_str(save_to_dir)
c_file_name = _encode_str(file_name)
err = LIBECONF.econf_writeFile(byref(ef._ptr), c_save_to_dir, c_file_name)
return Econf_err(err)
if err:
_exceptions(err, f"write_file failed with error: {err_string(err)}")
return


def get_path(ef: EconfFile) -> str:
Expand Down Expand Up @@ -605,15 +607,15 @@ def get_bool_value_def(ef: EconfFile, group: str, key: str, default: bool) -> bo
return c_result.value


def set_int_value(ef: EconfFile, group: str, key: str, value: int) -> Econf_err:
def set_int_value(ef: EconfFile, group: str, key: str, value: int) -> None:
"""
Setting an integer value for given group/key
:param ef: Key-Value storage object
:param group: desired group
:param key: key of the value that is requested
:param value: value to be set for given key
:return: Error code
:return: Nothing
"""
if group:
group = _encode_str(group)
Expand All @@ -622,18 +624,18 @@ def set_int_value(ef: EconfFile, group: str, key: str, value: int) -> Econf_err:
err = LIBECONF.econf_setInt64Value(byref(ef._ptr), group, c_key, c_value)
if err:
_exceptions(err, f"set_int64_value failed with error: {err_string(err)}")
return Econf_err(err)
return


def set_uint_value(ef: EconfFile, group: str, key: str, value: int) -> Econf_err:
def set_uint_value(ef: EconfFile, group: str, key: str, value: int) -> None:
"""
Setting an unsigned integer value for given group/key
:param ef: Key-Value storage object
:param group: desired group
:param key: key of the value that is requested
:param value: value to be set for given key
:return: Error code
:return: Nothing
"""
if group:
group = _encode_str(group)
Expand All @@ -642,18 +644,18 @@ def set_uint_value(ef: EconfFile, group: str, key: str, value: int) -> Econf_err
err = LIBECONF.econf_setUInt64Value(byref(ef._ptr), group, c_key, c_value)
if err:
_exceptions(err, f"set_uint64_value failed with error: {err_string(err)}")
return Econf_err(err)
return


def set_float_value(ef: EconfFile, group: str, key: str, value: float) -> Econf_err:
def set_float_value(ef: EconfFile, group: str, key: str, value: float) -> None:
"""
Setting a float value for given group/key
:param ef: Key-Value storage object
:param group: desired group
:param key: key of the value that is requested
:param value: value to be set for given key
:return: Error code
:return: Nothing
"""
if group:
group = _encode_str(group)
Expand All @@ -664,20 +666,20 @@ def set_float_value(ef: EconfFile, group: str, key: str, value: float) -> Econf_
err = LIBECONF.econf_setDoubleValue(byref(ef._ptr), group, c_key, c_value)
if err:
_exceptions(err, f"set_double_value failed with error: {err_string(err)}")
return Econf_err(err)
return


def set_string_value(
ef: EconfFile, group: str, key: str, value: str | bytes
) -> Econf_err:
) -> None:
"""
Setting a string value for given group/key
:param ef: Key-Value storage object
:param group: desired group
:param key: key of the value that is requested
:param value: value to be set for given key
:return: Error code
:return: Nothing
"""
if group:
group = _encode_str(group)
Expand All @@ -686,18 +688,18 @@ def set_string_value(
err = LIBECONF.econf_setStringValue(byref(ef._ptr), group, c_key, c_value)
if err:
_exceptions(err, f"set_string_value failed with error: {err_string(err)}")
return Econf_err(err)
return


def set_bool_value(ef: EconfFile, group: str, key: str, value: bool) -> Econf_err:
def set_bool_value(ef: EconfFile, group: str, key: str, value: bool) -> None:
"""
Setting a boolean value for given group/key
:param ef: Key-Value storage object
:param group: desired group
:param key: key of the value that is requested
:param value: value to be set for given key
:return: Error code
:return: Nothing
"""
if group:
group = _encode_str(group)
Expand All @@ -708,7 +710,7 @@ def set_bool_value(ef: EconfFile, group: str, key: str, value: bool) -> Econf_er
err = LIBECONF.econf_setBoolValue(byref(ef._ptr), group, c_key, c_value)
if err:
_exceptions(err, f"set_bool_value failed with error: {err_string(err)}")
return Econf_err(err)
return


def err_string(error: int):
Expand All @@ -725,7 +727,7 @@ def err_string(error: int):
return LIBECONF.econf_errString(error).decode("utf-8")


def err_location():
def err_location() -> Tuple[str, int]:
"""
Info about the line where an error happened
Expand Down

0 comments on commit 373bc78

Please sign in to comment.