]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Simpler bool loader implementation
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 14 Nov 2020 03:25:23 +0000 (03:25 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 14 Nov 2020 03:25:23 +0000 (03:25 +0000)
psycopg3/psycopg3/types/singletons.py

index aa39ca42bf4e3353771bdbe7c093ca5b962f0782..f6de7e09ddb7f2b556cf93b22cf5a731504719c4 100644 (file)
@@ -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"