# Copyright (C) 2020 The Psycopg Team
import codecs
-from typing import (
- Any,
- Callable,
- cast,
- Dict,
- Generator,
- List,
- Optional,
- Sequence,
- Tuple,
- Union,
-)
+from typing import cast
+from typing import Any, Callable, Dict, Generator, List, Optional, Sequence
+from typing import Tuple, Union
from . import exceptions as exc
from .pq import Format, PGresult
# Type system
-AdaptContext = Union[BaseConnection, BaseCursor]
+AdaptContext = Union[None, BaseConnection, BaseCursor]
MaybeOid = Union[Optional[bytes], Tuple[Optional[bytes], Oid]]
AdapterFunc = Callable[[Any], MaybeOid]
def register(
cls: type,
adapter: AdapterType,
- context: Optional[AdaptContext] = None,
+ context: AdaptContext = None,
format: Format = Format.TEXT,
) -> AdapterType:
if not isinstance(cls, type):
@staticmethod
def register_binary(
- cls: type,
- adapter: AdapterType,
- context: Optional[AdaptContext] = None,
+ cls: type, adapter: AdapterType, context: AdaptContext = None,
) -> AdapterType:
return Adapter.register(cls, adapter, context, format=Format.BINARY)
def register(
oid: Oid,
caster: TypecasterType,
- context: Optional[AdaptContext] = None,
+ context: AdaptContext = None,
format: Format = Format.TEXT,
) -> TypecasterType:
if not isinstance(oid, int):
@staticmethod
def register_binary(
- oid: Oid,
- caster: TypecasterType,
- context: Optional[AdaptContext] = None,
+ oid: Oid, caster: TypecasterType, context: AdaptContext = None,
) -> TypecasterType:
return Typecaster.register(oid, caster, context, format=Format.BINARY)
connection: Optional[BaseConnection]
cursor: Optional[BaseCursor]
- def __init__(self, context: Optional[AdaptContext]):
+ def __init__(self, context: AdaptContext):
if context is None:
self.connection = None
self.cursor = None