Skip to content

autocast

Automatically detect the true Python type of a string and cast it to the correct type.

Based on https://github.com/cgreer/cgAutoCast/blob/master/cgAutoCast.py

Only used by Legacy configuration file parser.

Functions

autocast_value

autocast_value(var: Any) -> Any

Guess the string representation of the variable’s type.

Parameters:

var

Value to autocast.

TYPE: Any

Returns:

Any

The autocasted value.

boolify

boolify(s: str) -> bool

Convert a string to a boolean.

listify

listify(s: str) -> list

Convert a string representation of a list into list of homogeneous basic types.

Type of elements in list is determined via first element. Successive elements are cast to that type.

Parameters:

s

String representation of a list.

TYPE: str

Raises:

ValueError

If string does not represent a list.

TypeError

If string does not represent a list of homogeneous basic types.

Returns:

list

List of homogeneous basic types.

noneify

noneify(s: str) -> None

Convert a string to None.