]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/typing.py
add type annotations for token analysis
[nominatim.git] / nominatim / typing.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Type definitions for typing annotations.
9
10 Complex type definitions are moved here, to keep the source files readable.
11 """
12 from typing import Any, Union, Mapping, TypeVar, Sequence, TYPE_CHECKING
13
14 # Generics varaible names do not confirm to naming styles, ignore globally here.
15 # pylint: disable=invalid-name,abstract-method,multiple-statements,missing-class-docstring
16
17 if TYPE_CHECKING:
18     import psycopg2.sql
19     import psycopg2.extensions
20     import psycopg2.extras
21     import os
22
23 StrPath = Union[str, 'os.PathLike[str]']
24
25 SysEnv = Mapping[str, str]
26
27 # psycopg2-related types
28
29 Query = Union[str, bytes, 'psycopg2.sql.Composable']
30
31 T_ResultKey = TypeVar('T_ResultKey', int, str)
32
33 class DictCursorResult(Mapping[str, Any]):
34     def __getitem__(self, x: Union[int, str]) -> Any: ...
35
36 DictCursorResults = Sequence[DictCursorResult]
37
38 T_cursor = TypeVar('T_cursor', bound='psycopg2.extensions.cursor')