From: Daniele Varrazzo Date: Sat, 14 Nov 2020 03:25:23 +0000 (+0000) Subject: Simpler bool loader implementation X-Git-Tag: 3.0.dev0~363 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d09bea915737daca30dc09e4788f48888d716524;p=thirdparty%2Fpsycopg.git Simpler bool loader implementation --- diff --git a/psycopg3/psycopg3/types/singletons.py b/psycopg3/psycopg3/types/singletons.py index aa39ca42b..f6de7e09d 100644 --- a/psycopg3/psycopg3/types/singletons.py +++ b/psycopg3/psycopg3/types/singletons.py @@ -4,8 +4,6 @@ Adapters for None and boolean. # Copyright (C) 2020 The Psycopg Team -from typing import Dict - from ..oids import builtins from ..adapt import Dumper, Loader @@ -25,7 +23,7 @@ class BoolDumper(Dumper): @Dumper.binary(bool) -class BinaryBoolDumper(Dumper): +class BoolBinaryDumper(Dumper): oid = BOOL_OID @@ -46,19 +44,11 @@ class NoneDumper(Dumper): @Loader.text(builtins["bool"].oid) class BoolLoader(Loader): - def load( - self, - data: bytes, - __values: Dict[bytes, bool] = {b"t": True, b"f": False}, - ) -> bool: - return __values[data] + def load(self, data: bytes) -> bool: + return data == b"t" @Loader.binary(builtins["bool"].oid) -class BinaryBoolLoader(Loader): - def load( - self, - data: bytes, - __values: Dict[bytes, bool] = {b"\x01": True, b"\x00": False}, - ) -> bool: - return __values[data] +class BoolBinaryLoader(Loader): + def load(self, data: bytes) -> bool: + return data != b"\x00"