79170822

Date: 2024-11-08 16:22:30
Score: 2.5
Natty:
Report link

Here's my 2 cents: Why not use YAML?

Code:

import os, yaml

bool(yaml.load(os.getenv(MY_VAR) or "", yaml.Loader))

Test:

for val, expected in {
    "yes": True,
    "no": False,
    "on": True,
    "off": False,
    "true": True,
    "false": False,
    "1": True,
    "0": False,
    "": False,
    None: False,
}.items():
    actual = bool(yaml.load(val or "", yaml.Loader))
    assert actual == expected
Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Lariel