From 2c0f2e1eded166fa27471bc640420713a2bb964f Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Fri, 25 Oct 2024 17:56:47 +0200 Subject: [PATCH 1/1] remove now unnecessary type-ignores --- src/nominatim_api/search/db_search_lookups.py | 12 ++++---- src/nominatim_api/sql/sqlalchemy_functions.py | 30 +++++++++---------- .../sql/sqlalchemy_types/geometry.py | 28 ++++++++--------- .../sql/sqlalchemy_types/int_array.py | 10 +++---- .../sql/sqlalchemy_types/key_value.py | 4 +-- src/nominatim_api/types.py | 2 +- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/nominatim_api/search/db_search_lookups.py b/src/nominatim_api/search/db_search_lookups.py index 712cd894..4a21d51f 100644 --- a/src/nominatim_api/search/db_search_lookups.py +++ b/src/nominatim_api/search/db_search_lookups.py @@ -30,7 +30,7 @@ class LookupAll(LookupType): sa.type_coerce(tokens, IntArray)) -@compiles(LookupAll) # type: ignore[no-untyped-call, misc] +@compiles(LookupAll) def _default_lookup_all(element: LookupAll, compiler: 'sa.Compiled', **kw: Any) -> str: _, col, _, tokens = list(element.clauses) @@ -38,7 +38,7 @@ def _default_lookup_all(element: LookupAll, compiler.process(tokens, **kw)) -@compiles(LookupAll, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(LookupAll, 'sqlite') def _sqlite_lookup_all(element: LookupAll, compiler: 'sa.Compiled', **kw: Any) -> str: place, col, colname, tokens = list(element.clauses) @@ -69,14 +69,14 @@ class LookupAny(LookupType): super().__init__(table.c.place_id, getattr(table.c, column), column, sa.type_coerce(tokens, IntArray)) -@compiles(LookupAny) # type: ignore[no-untyped-call, misc] +@compiles(LookupAny) def _default_lookup_any(element: LookupAny, compiler: 'sa.Compiled', **kw: Any) -> str: _, col, _, tokens = list(element.clauses) return "(%s && %s)" % (compiler.process(col, **kw), compiler.process(tokens, **kw)) -@compiles(LookupAny, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(LookupAny, 'sqlite') def _sqlite_lookup_any(element: LookupAny, compiler: 'sa.Compiled', **kw: Any) -> str: place, _, colname, tokens = list(element.clauses) @@ -101,14 +101,14 @@ class Restrict(LookupType): sa.type_coerce(tokens, IntArray)) -@compiles(Restrict) # type: ignore[no-untyped-call, misc] +@compiles(Restrict) def _default_restrict(element: Restrict, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "(coalesce(null, %s) @> %s)" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) -@compiles(Restrict, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Restrict, 'sqlite') def _sqlite_restrict(element: Restrict, compiler: 'sa.Compiled', **kw: Any) -> str: return "array_contains(%s)" % compiler.process(element.clauses, **kw) diff --git a/src/nominatim_api/sql/sqlalchemy_functions.py b/src/nominatim_api/sql/sqlalchemy_functions.py index 7abe7d3f..094c33dc 100644 --- a/src/nominatim_api/sql/sqlalchemy_functions.py +++ b/src/nominatim_api/sql/sqlalchemy_functions.py @@ -28,7 +28,7 @@ class PlacexGeometryReverseLookuppolygon(sa.sql.functions.GenericFunction[Any]): inherit_cache = True -@compiles(PlacexGeometryReverseLookuppolygon) # type: ignore[no-untyped-call, misc] +@compiles(PlacexGeometryReverseLookuppolygon) def _default_intersects(element: PlacexGeometryReverseLookuppolygon, compiler: 'sa.Compiled', **kw: Any) -> str: return ("(ST_GeometryType(placex.geometry) in ('ST_Polygon', 'ST_MultiPolygon')" @@ -39,7 +39,7 @@ def _default_intersects(element: PlacexGeometryReverseLookuppolygon, " AND placex.linked_place_id is null)") -@compiles(PlacexGeometryReverseLookuppolygon, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(PlacexGeometryReverseLookuppolygon, 'sqlite') def _sqlite_intersects(element: PlacexGeometryReverseLookuppolygon, compiler: 'sa.Compiled', **kw: Any) -> str: return ("(ST_GeometryType(placex.geometry) in ('POLYGON', 'MULTIPOLYGON')" @@ -60,7 +60,7 @@ class IntersectsReverseDistance(sa.sql.functions.GenericFunction[Any]): self.tablename = table.name -@compiles(IntersectsReverseDistance) # type: ignore[no-untyped-call, misc] +@compiles(IntersectsReverseDistance) def default_reverse_place_diameter(element: IntersectsReverseDistance, compiler: 'sa.Compiled', **kw: Any) -> str: table = element.tablename @@ -73,7 +73,7 @@ def default_reverse_place_diameter(element: IntersectsReverseDistance, tuple(map(lambda c: compiler.process(c, **kw), element.clauses)) -@compiles(IntersectsReverseDistance, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(IntersectsReverseDistance, 'sqlite') def sqlite_reverse_place_diameter(element: IntersectsReverseDistance, compiler: 'sa.Compiled', **kw: Any) -> str: geom1, rank, geom2 = list(element.clauses) @@ -101,7 +101,7 @@ class IsBelowReverseDistance(sa.sql.functions.GenericFunction[Any]): inherit_cache = True -@compiles(IsBelowReverseDistance) # type: ignore[no-untyped-call, misc] +@compiles(IsBelowReverseDistance) def default_is_below_reverse_distance(element: IsBelowReverseDistance, compiler: 'sa.Compiled', **kw: Any) -> str: dist, rank = list(element.clauses) @@ -109,7 +109,7 @@ def default_is_below_reverse_distance(element: IsBelowReverseDistance, compiler.process(rank, **kw)) -@compiles(IsBelowReverseDistance, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(IsBelowReverseDistance, 'sqlite') def sqlite_is_below_reverse_distance(element: IsBelowReverseDistance, compiler: 'sa.Compiled', **kw: Any) -> str: dist, rank = list(element.clauses) @@ -126,7 +126,7 @@ class IsAddressPoint(sa.sql.functions.GenericFunction[Any]): table.c.housenumber, table.c.name) -@compiles(IsAddressPoint) # type: ignore[no-untyped-call, misc] +@compiles(IsAddressPoint) def default_is_address_point(element: IsAddressPoint, compiler: 'sa.Compiled', **kw: Any) -> str: rank, hnr, name = list(element.clauses) @@ -136,7 +136,7 @@ def default_is_address_point(element: IsAddressPoint, compiler.process(name, **kw)) -@compiles(IsAddressPoint, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(IsAddressPoint, 'sqlite') def sqlite_is_address_point(element: IsAddressPoint, compiler: 'sa.Compiled', **kw: Any) -> str: rank, hnr, name = list(element.clauses) @@ -153,7 +153,7 @@ class CrosscheckNames(sa.sql.functions.GenericFunction[Any]): name = 'CrosscheckNames' inherit_cache = True -@compiles(CrosscheckNames) # type: ignore[no-untyped-call, misc] +@compiles(CrosscheckNames) def compile_crosscheck_names(element: CrosscheckNames, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) @@ -161,7 +161,7 @@ def compile_crosscheck_names(element: CrosscheckNames, compiler.process(arg1, **kw), compiler.process(arg2, **kw)) -@compiles(CrosscheckNames, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(CrosscheckNames, 'sqlite') def compile_sqlite_crosscheck_names(element: CrosscheckNames, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) @@ -178,12 +178,12 @@ class JsonArrayEach(sa.sql.functions.GenericFunction[Any]): inherit_cache = True -@compiles(JsonArrayEach) # type: ignore[no-untyped-call, misc] +@compiles(JsonArrayEach) def default_json_array_each(element: JsonArrayEach, compiler: 'sa.Compiled', **kw: Any) -> str: return "json_array_elements(%s)" % compiler.process(element.clauses, **kw) -@compiles(JsonArrayEach, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(JsonArrayEach, 'sqlite') def sqlite_json_array_each(element: JsonArrayEach, compiler: 'sa.Compiled', **kw: Any) -> str: return "json_each(%s)" % compiler.process(element.clauses, **kw) @@ -196,7 +196,7 @@ class Greatest(sa.sql.functions.GenericFunction[Any]): inherit_cache = True -@compiles(Greatest, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Greatest, 'sqlite') def sqlite_greatest(element: Greatest, compiler: 'sa.Compiled', **kw: Any) -> str: return "max(%s)" % compiler.process(element.clauses, **kw) @@ -209,13 +209,13 @@ class RegexpWord(sa.sql.functions.GenericFunction[Any]): inherit_cache = True -@compiles(RegexpWord, 'postgresql') # type: ignore[no-untyped-call, misc] +@compiles(RegexpWord, 'postgresql') def postgres_regexp_nocase(element: RegexpWord, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "%s ~* ('\\m(' || %s || ')\\M')::text" % (compiler.process(arg2, **kw), compiler.process(arg1, **kw)) -@compiles(RegexpWord, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(RegexpWord, 'sqlite') def sqlite_regexp_nocase(element: RegexpWord, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "regexp('\\b(' || %s || ')\\b', %s)" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) diff --git a/src/nominatim_api/sql/sqlalchemy_types/geometry.py b/src/nominatim_api/sql/sqlalchemy_types/geometry.py index 48c82ee0..15b79a23 100644 --- a/src/nominatim_api/sql/sqlalchemy_types/geometry.py +++ b/src/nominatim_api/sql/sqlalchemy_types/geometry.py @@ -27,7 +27,7 @@ class Geometry_DistanceSpheroid(sa.sql.expression.FunctionElement[float]): inherit_cache = True -@compiles(Geometry_DistanceSpheroid) # type: ignore[no-untyped-call, misc] +@compiles(Geometry_DistanceSpheroid) def _default_distance_spheroid(element: Geometry_DistanceSpheroid, compiler: 'sa.Compiled', **kw: Any) -> str: return "ST_DistanceSpheroid(%s,"\ @@ -35,7 +35,7 @@ def _default_distance_spheroid(element: Geometry_DistanceSpheroid, % compiler.process(element.clauses, **kw) -@compiles(Geometry_DistanceSpheroid, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Geometry_DistanceSpheroid, 'sqlite') def _spatialite_distance_spheroid(element: Geometry_DistanceSpheroid, compiler: 'sa.Compiled', **kw: Any) -> str: return "COALESCE(Distance(%s, true), 0.0)" % compiler.process(element.clauses, **kw) @@ -48,14 +48,14 @@ class Geometry_IsLineLike(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(Geometry_IsLineLike) # type: ignore[no-untyped-call, misc] +@compiles(Geometry_IsLineLike) def _default_is_line_like(element: Geometry_IsLineLike, compiler: 'sa.Compiled', **kw: Any) -> str: return "ST_GeometryType(%s) IN ('ST_LineString', 'ST_MultiLineString')" % \ compiler.process(element.clauses, **kw) -@compiles(Geometry_IsLineLike, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Geometry_IsLineLike, 'sqlite') def _sqlite_is_line_like(element: Geometry_IsLineLike, compiler: 'sa.Compiled', **kw: Any) -> str: return "ST_GeometryType(%s) IN ('LINESTRING', 'MULTILINESTRING')" % \ @@ -69,14 +69,14 @@ class Geometry_IsAreaLike(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(Geometry_IsAreaLike) # type: ignore[no-untyped-call, misc] +@compiles(Geometry_IsAreaLike) def _default_is_area_like(element: Geometry_IsAreaLike, compiler: 'sa.Compiled', **kw: Any) -> str: return "ST_GeometryType(%s) IN ('ST_Polygon', 'ST_MultiPolygon')" % \ compiler.process(element.clauses, **kw) -@compiles(Geometry_IsAreaLike, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Geometry_IsAreaLike, 'sqlite') def _sqlite_is_area_like(element: Geometry_IsAreaLike, compiler: 'sa.Compiled', **kw: Any) -> str: return "ST_GeometryType(%s) IN ('POLYGON', 'MULTIPOLYGON')" % \ @@ -90,14 +90,14 @@ class Geometry_IntersectsBbox(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(Geometry_IntersectsBbox) # type: ignore[no-untyped-call, misc] +@compiles(Geometry_IntersectsBbox) def _default_intersects(element: Geometry_IntersectsBbox, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "%s && %s" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) -@compiles(Geometry_IntersectsBbox, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Geometry_IntersectsBbox, 'sqlite') def _sqlite_intersects(element: Geometry_IntersectsBbox, compiler: 'sa.Compiled', **kw: Any) -> str: return "MbrIntersects(%s) = 1" % compiler.process(element.clauses, **kw) @@ -113,14 +113,14 @@ class Geometry_ColumnIntersectsBbox(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(Geometry_ColumnIntersectsBbox) # type: ignore[no-untyped-call, misc] +@compiles(Geometry_ColumnIntersectsBbox) def default_intersects_column(element: Geometry_ColumnIntersectsBbox, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "%s && %s" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) -@compiles(Geometry_ColumnIntersectsBbox, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Geometry_ColumnIntersectsBbox, 'sqlite') def spatialite_intersects_column(element: Geometry_ColumnIntersectsBbox, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) @@ -144,12 +144,12 @@ class Geometry_ColumnDWithin(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(Geometry_ColumnDWithin) # type: ignore[no-untyped-call, misc] +@compiles(Geometry_ColumnDWithin) def default_dwithin_column(element: Geometry_ColumnDWithin, compiler: 'sa.Compiled', **kw: Any) -> str: return "ST_DWithin(%s)" % compiler.process(element.clauses, **kw) -@compiles(Geometry_ColumnDWithin, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(Geometry_ColumnDWithin, 'sqlite') def spatialite_dwithin_column(element: Geometry_ColumnDWithin, compiler: 'sa.Compiled', **kw: Any) -> str: geom1, geom2, dist = list(element.clauses) @@ -275,7 +275,7 @@ class Geometry(types.UserDefinedType): # type: ignore[type-arg] return Geometry_DistanceSpheroid(self, other) -@compiles(Geometry, 'sqlite') # type: ignore[no-untyped-call] +@compiles(Geometry, 'sqlite') def get_col_spec(self, *args, **kwargs): # type: ignore[no-untyped-def] return 'GEOMETRY' @@ -302,7 +302,7 @@ def _add_function_alias(func: str, ftype: type, alias: str) -> None: def _sqlite_impl(element: Any, compiler: Any, **kw: Any) -> Any: return func_templ % compiler.process(element.clauses, **kw) - compiles(_FuncDef, 'sqlite')(_sqlite_impl) # type: ignore[no-untyped-call] + compiles(_FuncDef, 'sqlite')(_sqlite_impl) for alias in SQLITE_FUNCTION_ALIAS: _add_function_alias(*alias) diff --git a/src/nominatim_api/sql/sqlalchemy_types/int_array.py b/src/nominatim_api/sql/sqlalchemy_types/int_array.py index c76bc9fa..e53f8bfd 100644 --- a/src/nominatim_api/sql/sqlalchemy_types/int_array.py +++ b/src/nominatim_api/sql/sqlalchemy_types/int_array.py @@ -77,7 +77,7 @@ class ArrayAgg(sa.sql.functions.GenericFunction[Any]): inherit_cache = True -@compiles(ArrayAgg, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(ArrayAgg, 'sqlite') def sqlite_array_agg(element: ArrayAgg, compiler: 'sa.Compiled', **kw: Any) -> str: return "group_concat(%s, ',')" % compiler.process(element.clauses, **kw) @@ -90,14 +90,14 @@ class ArrayContains(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(ArrayContains) # type: ignore[no-untyped-call, misc] +@compiles(ArrayContains) def generic_array_contains(element: ArrayContains, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "(%s @> %s)" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) -@compiles(ArrayContains, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(ArrayContains, 'sqlite') def sqlite_array_contains(element: ArrayContains, compiler: 'sa.Compiled', **kw: Any) -> str: return "array_contains(%s)" % compiler.process(element.clauses, **kw) @@ -111,12 +111,12 @@ class ArrayCat(sa.sql.expression.FunctionElement[Any]): inherit_cache = True -@compiles(ArrayCat) # type: ignore[no-untyped-call, misc] +@compiles(ArrayCat) def generic_array_cat(element: ArrayCat, compiler: 'sa.Compiled', **kw: Any) -> str: return "array_cat(%s)" % compiler.process(element.clauses, **kw) -@compiles(ArrayCat, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(ArrayCat, 'sqlite') def sqlite_array_cat(element: ArrayCat, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "(%s || ',' || %s)" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) diff --git a/src/nominatim_api/sql/sqlalchemy_types/key_value.py b/src/nominatim_api/sql/sqlalchemy_types/key_value.py index 15e1f6c5..e8296d38 100644 --- a/src/nominatim_api/sql/sqlalchemy_types/key_value.py +++ b/src/nominatim_api/sql/sqlalchemy_types/key_value.py @@ -48,12 +48,12 @@ class KeyValueConcat(sa.sql.expression.FunctionElement[Any]): name = 'JsonConcat' inherit_cache = True -@compiles(KeyValueConcat) # type: ignore[no-untyped-call, misc] +@compiles(KeyValueConcat) def default_json_concat(element: KeyValueConcat, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "(%s || coalesce(%s, ''::hstore))" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) -@compiles(KeyValueConcat, 'sqlite') # type: ignore[no-untyped-call, misc] +@compiles(KeyValueConcat, 'sqlite') def sqlite_json_concat(element: KeyValueConcat, compiler: 'sa.Compiled', **kw: Any) -> str: arg1, arg2 = list(element.clauses) return "json_patch(%s, coalesce(%s, '{}'))" % (compiler.process(arg1, **kw), compiler.process(arg2, **kw)) diff --git a/src/nominatim_api/types.py b/src/nominatim_api/types.py index 6c8adeb8..0dea1d1b 100644 --- a/src/nominatim_api/types.py +++ b/src/nominatim_api/types.py @@ -434,7 +434,7 @@ class LookupDetails: else field.default if field.metadata and 'transform' in field.metadata: return field.metadata['transform'](v) - if not isinstance(v, field.type): + if not isinstance(v, field.type): # type: ignore[arg-type] raise UsageError(f"Parameter '{field.name}' needs to be of {field.type!s}.") return v -- 2.39.5