Skip to content

BoolVariable doesn't support 0 and 1 values. #5

@mojeto

Description

@mojeto
  • Typed Environment Configuration version: 0.1.3
  • Python version: 3.8.3
  • Operating System: alpine linux

Description

The only valid env values for BoolVariable are true and false (case insensitive) even distutils.util.strtobool used allows for more options

def strtobool (val):
    """Convert a string representation of truth to true (1) or false (0).

    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if
    'val' is anything else.
    """

issue is in typepy.converter._bool.BoolConverter.__strict_strtobool static method that ignores strtobool value and checks input value directly

binary_value = strtobool(lower_text)
if lower_text not in ["true", "false"]:
   # correct binary value ignored
    raise ValueError("invalid value '{}'".format(six.text_type(value)))

What I Did

DJANGO_DEBUG=1 python ./manage.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/typed_environment_configuration/typed_environment_configuration.py", line 32, in getenv
    return self._value_type(value, strict_level=self._strict_level).convert()
  File "/usr/local/lib/python3.8/site-packages/typepy/type/_base.py", line 120, in convert
    raise TypeConversionError(
typepy.error.TypeConversionError: failed to convert from str to BOOL

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions