From 317cc5c5443ef0a46b70be589fba2737d0685948 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Fri, 26 May 2023 18:09:03 +0200 Subject: [PATCH] make code backwards-compatible with older Python versions --- nominatim/api/search/db_searches.py | 4 ++-- nominatim/api/types.py | 6 ++++-- nominatim/api/v1/helpers.py | 13 +++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/nominatim/api/search/db_searches.py b/nominatim/api/search/db_searches.py index 107451b6..db35f726 100644 --- a/nominatim/api/search/db_searches.py +++ b/nominatim/api/search/db_searches.py @@ -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'), diff --git a/nominatim/api/types.py b/nominatim/api/types.py index 3579d7fa..c7e15843 100644 --- a/nominatim/api/types.py +++ b/nominatim/api/types.py @@ -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. """ diff --git a/nominatim/api/v1/helpers.py b/nominatim/api/v1/helpers.py index b9259ff2..62e5e943 100644 --- a/nominatim/api/v1/helpers.py +++ b/nominatim/api/v1/helpers.py @@ -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: -- 2.39.5