mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-14 18:37:58 +00:00
fix linting issues
This commit is contained in:
@@ -80,7 +80,8 @@ class BaseLogger:
|
||||
"""
|
||||
|
||||
def format_sql(self, conn: AsyncConnection, statement: 'sa.Executable',
|
||||
extra_params: Union[Mapping[str, Any], Sequence[Mapping[str, Any]], None]) -> str:
|
||||
extra_params: Union[Mapping[str, Any],
|
||||
Sequence[Mapping[str, Any]], None]) -> str:
|
||||
""" Return the comiled version of the statement.
|
||||
"""
|
||||
compiled = cast('sa.ClauseElement', statement).compile(conn.sync_engine)
|
||||
@@ -95,13 +96,14 @@ class BaseLogger:
|
||||
|
||||
sqlstr = str(compiled)
|
||||
|
||||
if '%s' in sqlstr:
|
||||
if sa.__version__.startswith('1'):
|
||||
try:
|
||||
return sqlstr % tuple((repr(compiled.params[name]) for name in compiled.positiontup))
|
||||
return sqlstr % tuple((repr(params.get(name, None))
|
||||
for name in compiled.positiontup)) # type: ignore
|
||||
except TypeError:
|
||||
return sqlstr
|
||||
|
||||
return str(compiled) % params
|
||||
return sqlstr % params
|
||||
|
||||
|
||||
class HTMLLogger(BaseLogger):
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
"""
|
||||
Implementation of reverse geocoding.
|
||||
"""
|
||||
from typing import Optional, List, Callable, Type, Tuple
|
||||
from typing import Optional, List, Callable, Type, Tuple, Dict, Any
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from nominatim.typing import SaColumn, SaSelect, SaFromClause, SaLabel, SaRow
|
||||
from nominatim.typing import SaColumn, SaSelect, SaFromClause, SaLabel, SaRow, SaBind
|
||||
from nominatim.api.connection import SearchConnection
|
||||
import nominatim.api.results as nres
|
||||
from nominatim.api.logging import log
|
||||
@@ -24,8 +24,8 @@ from nominatim.db.sqlalchemy_types import Geometry
|
||||
|
||||
RowFunc = Callable[[Optional[SaRow], Type[nres.ReverseResult]], Optional[nres.ReverseResult]]
|
||||
|
||||
WKT_PARAM = sa.bindparam('wkt', type_=Geometry)
|
||||
MAX_RANK_PARAM = sa.bindparam('max_rank')
|
||||
WKT_PARAM: SaBind = sa.bindparam('wkt', type_=Geometry)
|
||||
MAX_RANK_PARAM: SaBind = sa.bindparam('max_rank')
|
||||
|
||||
def _select_from_placex(t: SaFromClause, use_wkt: bool = True) -> SaSelect:
|
||||
""" Create a select statement with the columns relevant for reverse
|
||||
@@ -93,7 +93,7 @@ class ReverseGeocoder:
|
||||
self.conn = conn
|
||||
self.params = params
|
||||
|
||||
self.bind_params = {'max_rank': params.max_rank}
|
||||
self.bind_params: Dict[str, Any] = {'max_rank': params.max_rank}
|
||||
|
||||
|
||||
@property
|
||||
|
||||
@@ -14,7 +14,7 @@ import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import ARRAY, array_agg
|
||||
|
||||
from nominatim.typing import SaFromClause, SaScalarSelect, SaColumn, \
|
||||
SaExpression, SaSelect, SaRow
|
||||
SaExpression, SaSelect, SaRow, SaBind
|
||||
from nominatim.api.connection import SearchConnection
|
||||
from nominatim.api.types import SearchDetails, DataLayer, GeometryFormat, Bbox
|
||||
import nominatim.api.results as nres
|
||||
@@ -39,15 +39,15 @@ def _details_to_bind_params(details: SearchDetails) -> Dict[str, Any]:
|
||||
'countries': details.countries}
|
||||
|
||||
|
||||
LIMIT_PARAM = sa.bindparam('limit')
|
||||
MIN_RANK_PARAM = sa.bindparam('min_rank')
|
||||
MAX_RANK_PARAM = sa.bindparam('max_rank')
|
||||
VIEWBOX_PARAM = sa.bindparam('viewbox', type_=Geometry)
|
||||
VIEWBOX2_PARAM = sa.bindparam('viewbox2', type_=Geometry)
|
||||
NEAR_PARAM = sa.bindparam('near', type_=Geometry)
|
||||
NEAR_RADIUS_PARAM = sa.bindparam('near_radius')
|
||||
EXCLUDED_PARAM = sa.bindparam('excluded')
|
||||
COUNTRIES_PARAM = sa.bindparam('countries')
|
||||
LIMIT_PARAM: SaBind = sa.bindparam('limit')
|
||||
MIN_RANK_PARAM: SaBind = sa.bindparam('min_rank')
|
||||
MAX_RANK_PARAM: SaBind = sa.bindparam('max_rank')
|
||||
VIEWBOX_PARAM: SaBind = sa.bindparam('viewbox', type_=Geometry)
|
||||
VIEWBOX2_PARAM: SaBind = sa.bindparam('viewbox2', type_=Geometry)
|
||||
NEAR_PARAM: SaBind = sa.bindparam('near', type_=Geometry)
|
||||
NEAR_RADIUS_PARAM: SaBind = sa.bindparam('near_radius')
|
||||
EXCLUDED_PARAM: SaBind = sa.bindparam('excluded')
|
||||
COUNTRIES_PARAM: SaBind = sa.bindparam('countries')
|
||||
|
||||
def _select_placex(t: SaFromClause) -> SaSelect:
|
||||
return sa.select(t.c.place_id, t.c.osm_type, t.c.osm_id, t.c.name,
|
||||
|
||||
@@ -16,8 +16,6 @@ import math
|
||||
from struct import unpack
|
||||
from binascii import unhexlify
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from nominatim.errors import UsageError
|
||||
|
||||
# pylint: disable=no-member,too-many-boolean-expressions,too-many-instance-attributes
|
||||
@@ -192,7 +190,8 @@ class Bbox:
|
||||
""" Return the WKT representation of the Bbox. This
|
||||
is a simple polygon with four points.
|
||||
"""
|
||||
return 'POLYGON(({0} {1},{0} {3},{2} {3},{2} {1},{0} {1}))'.format(*self.coords)
|
||||
return 'POLYGON(({0} {1},{0} {3},{2} {3},{2} {1},{0} {1}))'\
|
||||
.format(*self.coords) # pylint: disable=consider-using-f-string
|
||||
|
||||
|
||||
@staticmethod
|
||||
@@ -445,6 +444,7 @@ class SearchDetails(LookupDetails):
|
||||
""" Restrict search to places with one of the given class/type categories.
|
||||
An empty list (the default) will disable this filter.
|
||||
"""
|
||||
viewbox_x2: Optional[Bbox] = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.viewbox is not None:
|
||||
@@ -452,8 +452,6 @@ class SearchDetails(LookupDetails):
|
||||
yext = (self.viewbox.maxlat - self.viewbox.minlat)/2
|
||||
self.viewbox_x2 = Bbox(self.viewbox.minlon - xext, self.viewbox.minlat - yext,
|
||||
self.viewbox.maxlon + xext, self.viewbox.maxlat + yext)
|
||||
else:
|
||||
self.viewbox_x2 = None
|
||||
|
||||
|
||||
def restrict_min_max_rank(self, new_min: int, new_max: int) -> None:
|
||||
|
||||
@@ -10,9 +10,11 @@ Custom types for SQLAlchemy.
|
||||
from typing import Callable, Any
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.types as types
|
||||
from sqlalchemy import types
|
||||
|
||||
from nominatim.typing import SaColumn
|
||||
from nominatim.typing import SaColumn, SaBind
|
||||
|
||||
#pylint: disable=all
|
||||
|
||||
class Geometry(types.UserDefinedType[Any]):
|
||||
""" Simplified type decorator for PostGIS geometry. This type
|
||||
@@ -44,13 +46,13 @@ class Geometry(types.UserDefinedType[Any]):
|
||||
return process
|
||||
|
||||
|
||||
def bind_expression(self, bindvalue: 'sa.BindParameter[Any]') -> SaColumn:
|
||||
def bind_expression(self, bindvalue: SaBind) -> SaColumn:
|
||||
return sa.func.ST_GeomFromText(bindvalue, type_=self)
|
||||
|
||||
|
||||
class comparator_factory(types.UserDefinedType.Comparator):
|
||||
|
||||
def intersects(self, other: SaColumn) -> SaColumn:
|
||||
def intersects(self, other: SaColumn) -> 'sa.Operators':
|
||||
return self.op('&&')(other)
|
||||
|
||||
def is_line_like(self) -> SaColumn:
|
||||
|
||||
@@ -70,3 +70,4 @@ SaExpression: TypeAlias = 'sa.ColumnElement[bool]'
|
||||
SaLabel: TypeAlias = 'sa.Label[Any]'
|
||||
SaFromClause: TypeAlias = 'sa.FromClause'
|
||||
SaSelectable: TypeAlias = 'sa.Selectable'
|
||||
SaBind: TypeAlias = 'sa.BindParameter[Any]'
|
||||
|
||||
Reference in New Issue
Block a user