]> git.openstreetmap.org Git - nominatim.git/commitdiff
make code backwards-compatible with older Python versions
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 26 May 2023 16:09:03 +0000 (18:09 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 26 May 2023 21:33:35 +0000 (23:33 +0200)
nominatim/api/search/db_searches.py
nominatim/api/types.py
nominatim/api/v1/helpers.py

index 107451b6cc50c57352d192e039623c41da550895..db35f7265427b1e7b957c468556de4f67e50ec44 100644 (file)
@@ -639,8 +639,8 @@ class PlaceSearch(AbstractSearch):
                                                                   numerals, details)
                                     ), else_=None)
             else:
-                interpol_sql = sa.literal(None)
-                tiger_sql = sa.literal(None)
+                interpol_sql = sa.literal_column('NULL')
+                tiger_sql = sa.literal_column('NULL')
 
             unsort = sa.select(inner, place_sql.scalar_subquery().label('placex_hnr'),
                                interpol_sql.label('interpol_hnr'),
index 3579d7fa3d8d62fd882a8ad7230a5c134918806e..c7e15843b551da95579b67f1389488d8b18d396e 100644 (file)
@@ -400,7 +400,8 @@ class SearchDetails(LookupDetails):
                                      )
     """ Highest address rank to return.
     """
-    layers: Optional[DataLayer] = None
+    layers: Optional[DataLayer] = dataclasses.field(default=None,
+                                                    metadata={'transform': lambda r : r})
     """ Filter which kind of data to include. When 'None' (the default) then
         filtering by layers is disabled.
     """
@@ -427,7 +428,8 @@ class SearchDetails(LookupDetails):
                                               metadata={'transform': Point.from_param})
     """ Order results by distance to the given point.
     """
-    near_radius: Optional[float] = None
+    near_radius: Optional[float] = dataclasses.field(default=None,
+                                              metadata={'transform': lambda r : r})
     """ Use near point as a filter and drop results outside the given
         radius. Radius is given in degrees WSG84.
     """
index b9259ff291660f9b7ba1b4716e3fd6be6f975038..62e5e943441c1b526994a78d7f6bfd0557723ea8 100644 (file)
@@ -52,7 +52,7 @@ def feature_type_to_rank(feature_type: Optional[str]) -> Tuple[int, int]:
     return FEATURE_TYPE_TO_RANK.get(feature_type, (0, 30))
 
 
-#pylint: disable=too-many-arguments
+#pylint: disable=too-many-arguments,too-many-branches
 def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any],
                        feature_type: Optional[str],
                        namedetails: bool, extratags: bool,
@@ -62,9 +62,14 @@ def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any],
     """
     parsed = SearchDetails.from_kwargs(details)
     if parsed.geometry_output != GeometryFormat.NONE:
-        for flag in parsed.geometry_output:
-            assert flag.name
-            queryparts[f'polygon_{flag.name.lower()}'] = '1'
+        if parsed.geometry_output & GeometryFormat.GEOJSON:
+            queryparts['polygon_geojson'] = '1'
+        if parsed.geometry_output & GeometryFormat.KML:
+            queryparts['polygon_kml'] = '1'
+        if parsed.geometry_output & GeometryFormat.SVG:
+            queryparts['polygon_svg'] = '1'
+        if parsed.geometry_output & GeometryFormat.TEXT:
+            queryparts['polygon_text'] = '1'
     if parsed.address_details:
         queryparts['addressdetails'] = '1'
     if namedetails: