]> git.openstreetmap.org Git - nominatim.git/commitdiff
define type for enivronment dictionaries
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 3 Jul 2022 15:38:11 +0000 (17:38 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 18 Jul 2022 07:47:57 +0000 (09:47 +0200)
nominatim/db/connection.py
nominatim/tools/exec_utils.py
nominatim/typing.py

index 8d9c742aaab9568be88c9c25b3ae75e2445ef710..10327725aa20b8d0fc2b2b973324706b31e09284 100644 (file)
@@ -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
index 6b0807921a1365a5fab7212bb4932502bf33eabf..4e6afdc21fd3b17375252b43ed4b053fd973b58c 100644 (file)
@@ -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)
index abecc53db8975c43e0f9a51a0edaf8003e1baac3..6d7549899bda1ae674c4ee42a0a717ea10eb0445 100644 (file)
@@ -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']