Skip to content

Commit

Permalink
remove now unnecessary type-ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Oct 25, 2024
1 parent ea98317 commit 2c0f2e1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 43 deletions.
12 changes: 6 additions & 6 deletions src/nominatim_api/search/db_search_lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def __init__(self, table: SaFromClause, column: str, tokens: List[int]) -> None:
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)
return "(%s @> %s)" % (compiler.process(col, **kw),
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)
Expand Down Expand Up @@ -69,14 +69,14 @@ def __init__(self, table: SaFromClause, column: str, tokens: List[int]) -> None:
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)
Expand All @@ -101,14 +101,14 @@ def __init__(self, table: SaFromClause, column: str, tokens: List[int]) -> None:
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)
30 changes: 15 additions & 15 deletions src/nominatim_api/sql/sqlalchemy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand All @@ -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')"
Expand All @@ -60,7 +60,7 @@ def __init__(self, table: sa.Table, geom: SaColumn) -> None:
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
Expand All @@ -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)
Expand Down Expand Up @@ -101,15 +101,15 @@ 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)
return "%s < reverse_place_diameter(%s)" % (compiler.process(dist, **kw),
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)
Expand All @@ -126,7 +126,7 @@ def __init__(self, table: sa.Table) -> None:
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)
Expand All @@ -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)
Expand All @@ -153,15 +153,15 @@ 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)
return "coalesce(avals(%s) && ARRAY(SELECT * FROM json_array_elements_text(%s)), false)" % (
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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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))
28 changes: 14 additions & 14 deletions src/nominatim_api/sql/sqlalchemy_types/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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,"\
" 'SPHEROID[\"WGS 84\",6378137,298.257223563, AUTHORITY[\"EPSG\",\"7030\"]]')"\
% 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)
Expand All @@ -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')" % \
Expand All @@ -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')" % \
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -275,7 +275,7 @@ def distance_spheroid(self, other: SaColumn) -> SaColumn:
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'

Expand All @@ -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)
10 changes: 5 additions & 5 deletions src/nominatim_api/sql/sqlalchemy_types/int_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/nominatim_api/sql/sqlalchemy_types/key_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/nominatim_api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _check_field(v: Any, field: 'dataclasses.Field[Any]') -> Any:
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

Expand Down

0 comments on commit 2c0f2e1

Please sign in to comment.