mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
make types compatible with older Python versions
This commit is contained in:
@@ -12,6 +12,7 @@ from contextvars import ContextVar
|
|||||||
import datetime as dt
|
import datetime as dt
|
||||||
import textwrap
|
import textwrap
|
||||||
import io
|
import io
|
||||||
|
import re
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
@@ -103,6 +104,9 @@ class BaseLogger:
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
return sqlstr
|
return sqlstr
|
||||||
|
|
||||||
|
# Fixes an odd issue with Python 3.7 where percentages are not
|
||||||
|
# quoted correctly.
|
||||||
|
sqlstr = re.sub(r'%(?!\()', '%%', sqlstr)
|
||||||
return sqlstr % params
|
return sqlstr % params
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"""
|
"""
|
||||||
Custom types for SQLAlchemy.
|
Custom types for SQLAlchemy.
|
||||||
"""
|
"""
|
||||||
from typing import Callable, Any
|
from typing import Callable, Any, cast
|
||||||
|
import sys
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
@@ -16,7 +17,7 @@ from nominatim.typing import SaColumn, SaBind
|
|||||||
|
|
||||||
#pylint: disable=all
|
#pylint: disable=all
|
||||||
|
|
||||||
class Geometry(types.UserDefinedType[Any]):
|
class Geometry(types.UserDefinedType): # type: ignore[type-arg]
|
||||||
""" Simplified type decorator for PostGIS geometry. This type
|
""" Simplified type decorator for PostGIS geometry. This type
|
||||||
only supports geometries in 4326 projection.
|
only supports geometries in 4326 projection.
|
||||||
"""
|
"""
|
||||||
@@ -35,7 +36,7 @@ class Geometry(types.UserDefinedType[Any]):
|
|||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
return 'SRID=4326;' + value
|
return 'SRID=4326;' + value
|
||||||
|
|
||||||
return 'SRID=4326;' + value.to_wkt()
|
return 'SRID=4326;' + cast(str, value.to_wkt())
|
||||||
return process
|
return process
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ class Geometry(types.UserDefinedType[Any]):
|
|||||||
return sa.func.ST_GeomFromText(bindvalue, type_=self)
|
return sa.func.ST_GeomFromText(bindvalue, type_=self)
|
||||||
|
|
||||||
|
|
||||||
class comparator_factory(types.UserDefinedType.Comparator):
|
class comparator_factory(types.UserDefinedType.Comparator): # type: ignore[type-arg]
|
||||||
|
|
||||||
def intersects(self, other: SaColumn) -> 'sa.Operators':
|
def intersects(self, other: SaColumn) -> 'sa.Operators':
|
||||||
return self.op('&&')(other)
|
return self.op('&&')(other)
|
||||||
|
|||||||
Reference in New Issue
Block a user