# Copyright (C) 2022 The Psycopg Team
-from typing import (
- TYPE_CHECKING,
- Any,
- Callable,
- Dict,
- Optional,
- Union,
- cast,
-)
-
-from .numeric import dump_int_to_numeric_binary
+from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast
from .. import postgres
from .._struct import pack_int2, pack_int4, pack_int8
from ..pq import Format
from .. import _struct
+from .numeric import dump_int_to_numeric_binary, _SpecialValuesDumper
+
if TYPE_CHECKING:
import numpy as np
class _NPIntDumper(Dumper):
- def dump(self, obj: Any) -> bytes:
+ def dump(self, obj: Any) -> Buffer:
return str(obj).encode()
- def quote(self, obj: Any) -> bytes:
+ def quote(self, obj: Any) -> Buffer:
value = self.dump(obj)
return value if obj >= 0 else b" " + value
NPULongLongDumper = NPUInt64Dumper
-class _SpecialValuesDumper(Dumper):
-
- _special: Dict[bytes, bytes] = {}
-
- def dump(self, obj: float) -> Buffer:
- return str(obj).encode()
-
- def quote(self, obj: float) -> Buffer:
- value = self.dump(obj)
-
- if value in self._special:
- return self._special[value]
-
- return value if obj >= 0 else b" " + value
-
-
class _NPFloatDumper(_SpecialValuesDumper):
_special = {