simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.63k stars 111 forks source link

mypy failures in CI #512

Closed simonw closed 1 year ago

simonw commented 1 year ago

https://github.com/simonw/sqlite-utils/actions/runs/3472012235 failed on Python 3.11:

Truncated output:

sqlite_utils/db.py:2467: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
sqlite_utils/db.py:2467: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
sqlite_utils/db.py:2530: error: Incompatible default for argument "where" (default has type "None", argument has type "str")  [assignment]
sqlite_utils/db.py:2530: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
sqlite_utils/db.py:2530: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
sqlite_utils/db.py:2658: error: Argument 1 to "count_where" of "Queryable" has incompatible type "Optional[str]"; expected "str"  [arg-type]
Found 23 errors in 1 file (checked 51 source files)

Best look at https://github.com/hauntsaninja/no_implicit_optional

simonw commented 1 year ago
sqlite-utils % pipx run no_implicit_optional .
Calculating full-repo metadata...
Executing codemod...
11.43s 98% complete, 0.24s estimated for 5 files to go...

Then:

Finished codemodding 239 files!
 - Transformed 239 files successfully.
 - Skipped 0 files.
 - Failed to codemod 0 files.
 - 0 warnings were generated.

Here's the diff:

 diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py
index a06f4b7..e819d17 100644
--- a/sqlite_utils/db.py
+++ b/sqlite_utils/db.py
@@ -297,12 +297,12 @@ class Database:

     def __init__(
         self,
-        filename_or_conn: Union[str, pathlib.Path, sqlite3.Connection] = None,
+        filename_or_conn: Optional[Union[str, pathlib.Path, sqlite3.Connection]] = None,
         memory: bool = False,
-        memory_name: str = None,
+        memory_name: Optional[str] = None,
         recreate: bool = False,
         recursive_triggers: bool = True,
-        tracer: Callable = None,
+        tracer: Optional[Callable] = None,
         use_counts_table: bool = False,
     ):
         assert (filename_or_conn is not None and (not memory and not memory_name)) or (
@@ -341,7 +341,7 @@ class Database:
         self.conn.close()

     @contextlib.contextmanager
-    def tracer(self, tracer: Callable = None):
+    def tracer(self, tracer: Optional[Callable] = None):
         """
         Context manager to temporarily set a tracer function - all executed SQL queries will
         be passed to this.
@@ -378,7 +378,7 @@ class Database:

     def register_function(
         self,
-        fn: Callable = None,
+        fn: Optional[Callable] = None,
         deterministic: bool = False,
         replace: bool = False,
         name: Optional[str] = None,
@@ -879,7 +879,7 @@ class Database:
         pk: Optional[Any] = None,
         foreign_keys: Optional[ForeignKeysType] = None,
         column_order: Optional[List[str]] = None,
-        not_null: Iterable[str] = None,
+        not_null: Optional[Iterable[str]] = None,
         defaults: Optional[Dict[str, Any]] = None,
         hash_id: Optional[str] = None,
         hash_id_columns: Optional[Iterable[str]] = None,
@@ -1129,7 +1129,7 @@ class Database:
             sql += " [{}]".format(name)
         self.execute(sql)

-    def init_spatialite(self, path: str = None) -> bool:
+    def init_spatialite(self, path: Optional[str] = None) -> bool:
         """
         The ``init_spatialite`` method will load and initialize the SpatiaLite extension.
         The ``path`` argument should be an absolute path to the compiled extension, which
@@ -1182,7 +1182,7 @@ class Queryable:

     def count_where(
         self,
-        where: str = None,
+        where: Optional[str] = None,
         where_args: Optional[Union[Iterable, dict]] = None,
     ) -> int:
         """
@@ -1213,12 +1213,12 @@ class Queryable:

     def rows_where(
         self,
-        where: str = None,
+        where: Optional[str] = None,
         where_args: Optional[Union[Iterable, dict]] = None,
-        order_by: str = None,
+        order_by: Optional[str] = None,
         select: str = "*",
-        limit: int = None,
-        offset: int = None,
+        limit: Optional[int] = None,
+        offset: Optional[int] = None,
     ) -> Generator[dict, None, None]:
         """
         Iterate over every row in this table or view that matches the specified where clause.
@@ -1251,11 +1251,11 @@ class Queryable:

     def pks_and_rows_where(
         self,
-        where: str = None,
+        where: Optional[str] = None,
         where_args: Optional[Union[Iterable, dict]] = None,
-        order_by: str = None,
-        limit: int = None,
-        offset: int = None,
+        order_by: Optional[str] = None,
+        limit: Optional[int] = None,
+        offset: Optional[int] = None,
     ) -> Generator[Tuple[Any, Dict], None, None]:
         """
         Like ``.rows_where()`` but returns ``(pk, row)`` pairs - ``pk`` can be a single value or tuple.
@@ -1345,7 +1345,7 @@ class Table(Queryable):
         pk: Optional[Any] = None,
         foreign_keys: Optional[ForeignKeysType] = None,
         column_order: Optional[List[str]] = None,
-        not_null: Iterable[str] = None,
+        not_null: Optional[Iterable[str]] = None,
         defaults: Optional[Dict[str, Any]] = None,
         batch_size: int = 100,
         hash_id: Optional[str] = None,
@@ -1545,7 +1545,7 @@ class Table(Queryable):
         pk: Optional[Any] = None,
         foreign_keys: Optional[ForeignKeysType] = None,
         column_order: Optional[List[str]] = None,
-        not_null: Iterable[str] = None,
+        not_null: Optional[Iterable[str]] = None,
         defaults: Optional[Dict[str, Any]] = None,
         hash_id: Optional[str] = None,
         hash_id_columns: Optional[Iterable[str]] = None,
@@ -2464,7 +2464,7 @@ class Table(Queryable):
         columns: Optional[Iterable[str]] = None,
         limit: Optional[int] = None,
         offset: Optional[int] = None,
-        where: str = None,
+        where: Optional[str] = None,
         where_args: Optional[Union[Iterable, dict]] = None,
         quote: bool = False,
     ) -> Generator[dict, None, None]:
@@ -2527,7 +2527,7 @@ class Table(Queryable):

     def delete_where(
         self,
-        where: str = None,
+        where: Optional[str] = None,
         where_args: Optional[Union[Iterable, dict]] = None,
         analyze: bool = False,
     ) -> "Table":
simonw commented 1 year ago

Test failed again: https://github.com/simonw/sqlite-utils/actions/runs/3476950474/jobs/5812663096

E: Failed to fetch http://azure.archive.ubuntu.com/ubuntu/pool/universe/s/spatialite/libsqlite3-mod-spatialite_4.3.0a-6build1_amd64.deb Unable to connect to azure.archive.ubuntu.com:http:

That looks like an intermittent error. I'll try running it again in the morning.

simonw commented 1 year ago

Tests passed.