]> git.openstreetmap.org Git - nominatim.git/commitdiff
adapt annotations for SQLAlchemy 2.x
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 27 Jan 2023 20:53:53 +0000 (21:53 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sat, 28 Jan 2023 10:51:26 +0000 (11:51 +0100)
It is not possible to produce type annotations that work with both
versions 1.4 and 2.0. So keep to the principle of only supporting
newest versions when it comes to mypy. This means that some types
may have to be string quoted to not cause issues when running with
SQLAlchemy 1.4.

.github/workflows/ci-tests.yml
docs/develop/Development-Environment.md
nominatim/api/connection.py
nominatim/api/core.py

index e7ba35f676f36157d266787c0e0a58d540435345..93cd9119431926500499af809b2f114bfc9dd298 100644 (file)
@@ -109,8 +109,8 @@ jobs:
             - name: Install Python webservers
               run: pip3 install falcon sanic sanic-testing sanic-cors starlette
 
-            - name: Install latest pylint/mypy
-              run: pip3 install -U pylint mypy types-PyYAML types-jinja2 types-psycopg2 types-psutil types-requests types-ujson typing-extensions asgi_lifespan sqlalchemy2-stubs
+            - name: Install latest pylint
+              run: pip3 install -U pylint asgi_lifespan
 
             - name: PHP linting
               run: phpcs --report-width=120 .
@@ -134,8 +134,8 @@ jobs:
                   python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build --format=progress3
               working-directory: Nominatim/test/bdd
 
-            - name: Install newer Python packages (for typechecking info)
-              run: pip3 install -U osmium uvicorn
+            - name: Install mypy and typechecking info
+              run: pip3 install -U mypy osmium uvicorn types-PyYAML types-jinja2 types-psycopg2 types-psutil types-requests types-ujson typing-extensions
               if: matrix.flavour != 'oldstuff'
 
             - name: Python static typechecking
index fc5008c4f7ebebfe872fa06cfbc382036c46f176..4bba30db12683a56bad76f4563384012a6628b05 100644 (file)
@@ -64,7 +64,7 @@ sudo apt install php-cgi phpunit php-codesniffer \
 
 pip3 install --user behave mkdocs mkdocstrings pytest pylint \
                     mypy types-PyYAML types-jinja2 types-psycopg2 types-psutil \
-                    types-ujosn \
+                    types-ujosn types-requests typing-extensions\
                     sanic-testing httpx asgi-lifespan
 ```
 
index 1502ba01f7f61825d1b628313dac85ff2fde8e17..b397f62413aa2686825725449f05c3def7239ade 100644 (file)
@@ -37,7 +37,7 @@ class SearchConnection:
 
     async def execute(self, sql: sa.sql.base.Executable,
                       params: Union[Mapping[str, Any], Sequence[Mapping[str, Any]], None] = None
-                     ) -> sa.engine.Result:
+                     ) -> 'sa.engine.Result[Any]':
         """ Execute a 'execute()' query on the connection.
         """
         return await self.connection.execute(sql, params)
index ae5bb5d8441f8a53912e61038e6c51efa5e549e1..a1f0e48df43df5c12ce1927588d65cb9dc4b2f08 100644 (file)
@@ -69,7 +69,7 @@ class NominatimAPIAsync:
                 self.server_version = 0
 
             if self.server_version >= 110000:
-                @sa.event.listens_for(engine.sync_engine, "connect") # type: ignore[misc]
+                @sa.event.listens_for(engine.sync_engine, "connect")
                 def _on_connect(dbapi_con: Any, _: Any) -> None:
                     cursor = dbapi_con.cursor()
                     cursor.execute("SET jit_above_cost TO '-1'")