]> git.openstreetmap.org Git - nominatim.git/commitdiff
fix backward compatibility issues with Python 3.7
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 25 Oct 2024 21:43:59 +0000 (23:43 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 25 Oct 2024 21:43:59 +0000 (23:43 +0200)
Makefile
src/nominatim_api/server/falcon/server.py
src/nominatim_api/v1/helpers.py

index cd7280fe193175eb2412f0de5719f32caf237ded..421b671a1cdd50506298f71bfc1c2373a5f828cd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ build-api:
 tests: mypy lint pytest bdd
 
 mypy:
-       mypy --strict src
+       mypy --strict --python-version 3.8 src
 
 pytest:
        pytest test/python
index c1196ddb5ae490547d252350670ea18e49a2eb72..558ff94338dba0c5f43d9deae9afa4ef57cbbb34 100644 (file)
@@ -7,7 +7,7 @@
 """
 Server implementation using the falcon webserver framework.
 """
-from typing import Optional, Mapping, cast, Any, List
+from typing import Optional, Mapping, Any, List
 from pathlib import Path
 import datetime as dt
 import asyncio
@@ -72,11 +72,11 @@ class ParamWrapper(ASGIAdaptor):
 
 
     def get(self, name: str, default: Optional[str] = None) -> Optional[str]:
-        return cast(Optional[str], self.request.get_param(name, default=default))
+        return self.request.get_param(name, default=default)
 
 
     def get_header(self, name: str, default: Optional[str] = None) -> Optional[str]:
-        return cast(Optional[str], self.request.get_header(name, default=default))
+        return self.request.get_header(name, default=default)
 
 
     def error(self, msg: str, status: int = 400) -> HTTPNominatimError:
@@ -91,7 +91,7 @@ class ParamWrapper(ASGIAdaptor):
 
 
     def base_uri(self) -> str:
-        return cast (str, self.request.forwarded_prefix)
+        return self.request.forwarded_prefix
 
     def config(self) -> Configuration:
         return self._config
@@ -183,7 +183,7 @@ def get_application(project_dir: Path,
     app.add_error_handler(HTTPNominatimError, nominatim_error_handler)
     app.add_error_handler(TimeoutError, timeout_error_handler)
     # different from TimeoutError in Python <= 3.10
-    app.add_error_handler(asyncio.TimeoutError, timeout_error_handler)
+    app.add_error_handler(asyncio.TimeoutError, timeout_error_handler) # type: ignore[arg-type]
 
     legacy_urls = api.config.get_bool('SERVE_LEGACY_URLS')
     formatter = load_format_dispatcher('v1', project_dir)
index 9c2208348c9926573e31584f918786a2068ab19f..4e1e4e5577d38ebf067b69d4ed1b83bf4809aa2e 100644 (file)
@@ -62,13 +62,13 @@ def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any],
     """
     parsed = SearchDetails.from_kwargs(details)
     if parsed.geometry_output != GeometryFormat.NONE:
-        if GeometryFormat.GEOJSON in parsed.geometry_output:
+        if GeometryFormat.GEOJSON & parsed.geometry_output:
             queryparts['polygon_geojson'] = '1'
-        if GeometryFormat.KML in parsed.geometry_output:
+        if GeometryFormat.KML & parsed.geometry_output:
             queryparts['polygon_kml'] = '1'
-        if GeometryFormat.SVG in parsed.geometry_output:
+        if GeometryFormat.SVG & parsed.geometry_output:
             queryparts['polygon_svg'] = '1'
-        if GeometryFormat.TEXT in parsed.geometry_output:
+        if GeometryFormat.TEXT & parsed.geometry_output:
             queryparts['polygon_text'] = '1'
     if parsed.address_details:
         queryparts['addressdetails'] = '1'