Don't str(None)

This commit is contained in:
əlemi 2022-05-23 02:22:19 +02:00
parent d2a13360a8
commit 6364f52d0b
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -4,7 +4,7 @@ import asyncio
import datetime import datetime
import pkg_resources import pkg_resources
from typing import List, Dict, Any, Type from typing import List, Dict, Any, Type, Optional
from time import time from time import time
from configparser import ConfigParser from configparser import ConfigParser
@ -55,7 +55,7 @@ class Treepuncher(
authenticator : AuthInterface authenticator : AuthInterface
def opt(k:str, required=False, default=None, t:type=str) -> Any: def opt(k:str, required=False, default=None, t:type=str) -> Optional[Any]:
v = kwargs.get(k) v = kwargs.get(k)
if v is None: if v is None:
v = self.cfg.get(k) v = self.cfg.get(k)
@ -65,6 +65,8 @@ class Treepuncher(
raise MissingParameterError(f"Missing configuration parameter '{k}'") raise MissingParameterError(f"Missing configuration parameter '{k}'")
if t is bool and isinstance(v, str) and v.lower().strip() == 'false': # hardcoded special case if t is bool and isinstance(v, str) and v.lower().strip() == 'false': # hardcoded special case
return False return False
if v is None:
return None
return t(v) return t(v)
if not opt('online_mode', default=True, t=bool): if not opt('online_mode', default=True, t=bool):