]> git.openstreetmap.org Git - nominatim.git/commitdiff
fix linting issues
authorSarah Hoffmann <lonvia@denofr.de>
Sat, 1 Jul 2023 16:02:46 +0000 (18:02 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 1 Jul 2023 18:18:59 +0000 (20:18 +0200)
nominatim/api/logging.py
nominatim/api/reverse.py
nominatim/api/search/db_searches.py
nominatim/api/types.py
nominatim/db/sqlalchemy_types.py
nominatim/typing.py

index 202d7de9a5baf0abca6ed1807bfb488cb136de05..3160ede8f53b01027ee17ffd8ef01d497f38fc9e 100644 (file)
@@ -80,7 +80,8 @@ class BaseLogger:
         """
 
     def format_sql(self, conn: AsyncConnection, statement: 'sa.Executable',
         """
 
     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)
         """ 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)
 
 
         sqlstr = str(compiled)
 
-        if '%s' in sqlstr:
+        if sa.__version__.startswith('1'):
             try:
             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
 
             except TypeError:
                 return sqlstr
 
-        return str(compiled) % params
+        return sqlstr % params
 
 
 class HTMLLogger(BaseLogger):
 
 
 class HTMLLogger(BaseLogger):
index 62239a540afb62b4716a20fff957db680a802e64..00605d45b3841ad5742e25287bb2d956fd1f10ad 100644 (file)
@@ -7,11 +7,11 @@
 """
 Implementation of reverse geocoding.
 """
 """
 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
 
 
 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
 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]]
 
 
 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
 
 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.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
 
 
     @property
index fc3f9e0945e7d6ef39d66fc1871bc5d708d1b544..cea19c852836ac7490b33e0511cc574e86ef317a 100644 (file)
@@ -14,7 +14,7 @@ import sqlalchemy as sa
 from sqlalchemy.dialects.postgresql import ARRAY, array_agg
 
 from nominatim.typing import SaFromClause, SaScalarSelect, SaColumn, \
 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
 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}
 
 
             '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,
 
 def _select_placex(t: SaFromClause) -> SaSelect:
     return sa.select(t.c.place_id, t.c.osm_type, t.c.osm_id, t.c.name,
index 60495dd08ac2a530614499217dd19ac1f414e162..43e83c1f689dfadda882a85aa79fe496cf0cfecf 100644 (file)
@@ -16,8 +16,6 @@ import math
 from struct import unpack
 from binascii import unhexlify
 
 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
 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 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
 
 
     @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.
     """
     """ 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:
 
     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)
             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:
 
 
     def restrict_min_max_rank(self, new_min: int, new_max: int) -> None:
index c54d339e6d903b202ec1ad7e551ee881681c8856..f5ec82bdbc4ef24b46d357c5ea060195b6302e68 100644 (file)
@@ -10,9 +10,11 @@ Custom types for SQLAlchemy.
 from typing import Callable, Any
 
 import sqlalchemy as sa
 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
 
 class Geometry(types.UserDefinedType[Any]):
     """ Simplified type decorator for PostGIS geometry. This type
@@ -44,13 +46,13 @@ class Geometry(types.UserDefinedType[Any]):
         return process
 
 
         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):
 
         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:
             return self.op('&&')(other)
 
         def is_line_like(self) -> SaColumn:
index d988fe04a3e3d56fb4af801fa4f3cb076c685a4e..ebb5e1e9d56f05fe91e52dda6c73d59365afee81 100644 (file)
@@ -70,3 +70,4 @@ SaExpression: TypeAlias = 'sa.ColumnElement[bool]'
 SaLabel: TypeAlias = 'sa.Label[Any]'
 SaFromClause: TypeAlias = 'sa.FromClause'
 SaSelectable: TypeAlias = 'sa.Selectable'
 SaLabel: TypeAlias = 'sa.Label[Any]'
 SaFromClause: TypeAlias = 'sa.FromClause'
 SaSelectable: TypeAlias = 'sa.Selectable'
+SaBind: TypeAlias = 'sa.BindParameter[Any]'