2022-07-02 12:59:19 +03:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#
|
|
|
|
# This file is part of Nominatim. (https://nominatim.org)
|
|
|
|
#
|
2023-02-01 11:56:33 +03:00
|
|
|
# Copyright (C) 2023 by the Nominatim developer community.
|
2022-07-02 12:59:19 +03:00
|
|
|
# For a full list of authors see the git log.
|
|
|
|
"""
|
|
|
|
Type definitions for typing annotations.
|
|
|
|
|
|
|
|
Complex type definitions are moved here, to keep the source files readable.
|
|
|
|
"""
|
2022-07-12 19:40:51 +03:00
|
|
|
from typing import Any, Union, Mapping, TypeVar, Sequence, TYPE_CHECKING
|
2022-07-02 12:59:19 +03:00
|
|
|
|
2022-07-20 17:05:25 +03:00
|
|
|
# Generics variable names do not confirm to naming styles, ignore globally here.
|
2022-07-18 00:18:55 +03:00
|
|
|
# pylint: disable=invalid-name,abstract-method,multiple-statements
|
|
|
|
# pylint: disable=missing-class-docstring,useless-import-alias
|
2022-07-02 12:59:19 +03:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
import psycopg2.sql
|
|
|
|
import psycopg2.extensions
|
2022-07-12 19:40:51 +03:00
|
|
|
import psycopg2.extras
|
2022-07-02 12:59:19 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
StrPath = Union[str, 'os.PathLike[str]']
|
|
|
|
|
2022-07-03 18:38:11 +03:00
|
|
|
SysEnv = Mapping[str, str]
|
|
|
|
|
2022-07-02 12:59:19 +03:00
|
|
|
# psycopg2-related types
|
|
|
|
|
|
|
|
Query = Union[str, bytes, 'psycopg2.sql.Composable']
|
2022-07-12 19:40:51 +03:00
|
|
|
|
|
|
|
T_ResultKey = TypeVar('T_ResultKey', int, str)
|
|
|
|
|
|
|
|
class DictCursorResult(Mapping[str, Any]):
|
|
|
|
def __getitem__(self, x: Union[int, str]) -> Any: ...
|
|
|
|
|
|
|
|
DictCursorResults = Sequence[DictCursorResult]
|
|
|
|
|
2022-07-02 12:59:19 +03:00
|
|
|
T_cursor = TypeVar('T_cursor', bound='psycopg2.extensions.cursor')
|
2022-07-18 00:18:55 +03:00
|
|
|
|
|
|
|
# The following typing features require typing_extensions to work
|
|
|
|
# on all supported Python versions.
|
|
|
|
# Only require this for type checking but not for normal operations.
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from typing_extensions import (Protocol as Protocol,
|
|
|
|
Final as Final,
|
|
|
|
TypedDict as TypedDict)
|
|
|
|
else:
|
|
|
|
Protocol = object
|
|
|
|
Final = 'Final'
|
|
|
|
TypedDict = dict
|
2023-02-01 11:56:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
# SQLAlchemy introduced generic types in version 2.0 making typing
|
2023-03-22 02:07:17 +03:00
|
|
|
# incompatible with older versions. Add wrappers here so we don't have
|
2023-02-01 11:56:33 +03:00
|
|
|
# to litter the code with bare-string types.
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from typing_extensions import (TypeAlias as TypeAlias)
|
|
|
|
else:
|
|
|
|
TypeAlias = str
|
|
|
|
|
|
|
|
SaSelect: TypeAlias = 'sa.Select[Any]'
|
|
|
|
SaRow: TypeAlias = 'sa.Row[Any]'
|
2023-03-24 00:38:37 +03:00
|
|
|
SaColumn: TypeAlias = 'sa.ColumnElement[Any]'
|
2023-02-01 11:56:33 +03:00
|
|
|
SaLabel: TypeAlias = 'sa.Label[Any]'
|
2023-03-24 00:38:37 +03:00
|
|
|
SaFromClause: TypeAlias = 'sa.FromClause'
|
|
|
|
SaSelectable: TypeAlias = 'sa.Selectable'
|