HBNetwork / python-decouple

Strict separation of config from code.
MIT License
2.83k stars 196 forks source link

Change strtobool to ignore the to bool conversion #135

Closed luzfcb closed 2 years ago

luzfcb commented 2 years ago

Change strtobool to ignore the to-bool conversion when the input value is a bool

This pull-request prevents an error from being thrown if the default value is used and it is a bool instead of a string.

Quick way to reproduce the error:

from decouple import config, strtobool

DEBUG = config('DEBUG', default=False, cast=strtobool)
    DEBUG = config('DEBUG', default=False, cast=strtobool)
  File "/home/luzfcb/.virtualenvs/myenv/lib/python3.9/site-packages/decouple.py", line 197, in __call__
    return self.config(*args, **kwargs)
  File "/home/luzfcb/.virtualenvs/myenv/lib/python3.9/site-packages/decouple.py", line 85, in __call__
    return self.get(*args, **kwargs)
  File "/home/luzfcb/.virtualenvs/myenv/lib/python3.9/site-packages/decouple.py", line 79, in get
    return cast(value)
  File "/home/luzfcb/.virtualenvs/myenv/lib/python3.9/site-packages/decouple.py, line 36, in strtobool
    value = value.lower()
AttributeError: 'bool' object has no attribute 'lower'

Process finished with exit code 1