forked from hans/Nominatim
define type for enivronment dictionaries
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"""
|
||||
Specialised connection and cursor functions.
|
||||
"""
|
||||
from typing import List, Optional, Any, Callable, ContextManager, Dict, Mapping, cast, overload, Tuple
|
||||
from typing import List, Optional, Any, Callable, ContextManager, Dict, cast, overload, Tuple
|
||||
import contextlib
|
||||
import logging
|
||||
import os
|
||||
@@ -17,7 +17,7 @@ import psycopg2.extensions
|
||||
import psycopg2.extras
|
||||
from psycopg2 import sql as pysql
|
||||
|
||||
from nominatim.typing import Query, T_cursor
|
||||
from nominatim.typing import SysEnv, Query, T_cursor
|
||||
from nominatim.errors import UsageError
|
||||
|
||||
LOG = logging.getLogger()
|
||||
@@ -225,7 +225,7 @@ _PG_CONNECTION_STRINGS = {
|
||||
|
||||
|
||||
def get_pg_env(dsn: str,
|
||||
base_env: Optional[Mapping[str, str]] = None) -> Dict[str, str]:
|
||||
base_env: Optional[SysEnv] = None) -> Dict[str, str]:
|
||||
""" Return a copy of `base_env` with the environment variables for
|
||||
PostgresSQL set up from the given database connection string.
|
||||
If `base_env` is None, then the OS environment is used as a base
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"""
|
||||
Helper functions for executing external programs.
|
||||
"""
|
||||
from typing import Any, Union, Optional, Mapping
|
||||
from typing import Any, Union, Optional, Mapping, IO
|
||||
from pathlib import Path
|
||||
import logging
|
||||
import subprocess
|
||||
@@ -160,7 +160,8 @@ def get_url(url: str) -> str:
|
||||
headers = {"User-Agent": f"Nominatim/{version_str()}"}
|
||||
|
||||
try:
|
||||
with urlrequest.urlopen(urlrequest.Request(url, headers=headers)) as response:
|
||||
request = urlrequest.Request(url, headers=headers)
|
||||
with urlrequest.urlopen(request) as response: # type: IO[bytes]
|
||||
return response.read().decode('utf-8')
|
||||
except Exception:
|
||||
LOG.fatal('Failed to load URL: %s', url)
|
||||
|
||||
@@ -9,7 +9,7 @@ Type definitions for typing annotations.
|
||||
|
||||
Complex type definitions are moved here, to keep the source files readable.
|
||||
"""
|
||||
from typing import Union, TypeVar, TYPE_CHECKING
|
||||
from typing import Union, Mapping, TypeVar, TYPE_CHECKING
|
||||
|
||||
# Generics varaible names do not confirm to naming styles, ignore globally here.
|
||||
# pylint: disable=invalid-name
|
||||
@@ -21,6 +21,8 @@ if TYPE_CHECKING:
|
||||
|
||||
StrPath = Union[str, 'os.PathLike[str]']
|
||||
|
||||
SysEnv = Mapping[str, str]
|
||||
|
||||
# psycopg2-related types
|
||||
|
||||
Query = Union[str, bytes, 'psycopg2.sql.Composable']
|
||||
|
||||
Reference in New Issue
Block a user