Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use mypy 1.0 #15052

Merged
merged 19 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
try:
from canonicaljson import set_json_library

set_json_library(json)
# type-ignore: I think there has been a regression in mypy 1.0.0 in how it checks
# modules against Protocols.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
set_json_library(json) # type: ignore[arg-type]
except ImportError:
pass

Expand Down
6 changes: 4 additions & 2 deletions synapse/storage/engines/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
IncorrectDatabaseSetup,
IsolationLevel,
)
from synapse.storage.types import Cursor
from synapse.storage.types import Cursor, DBAPI2Module

if TYPE_CHECKING:
from synapse.storage.database import LoggingDatabaseConnection
Expand All @@ -35,7 +35,9 @@ class PostgresEngine(
BaseDatabaseEngine[psycopg2.extensions.connection, psycopg2.extensions.cursor]
):
def __init__(self, database_config: Mapping[str, Any]):
super().__init__(psycopg2, database_config)
# Cast: mypy 1.0.0 doesn't seem to think that the module implements the protocol.
# AFAICS this is a false positive.
super().__init__(cast(DBAPI2Module, psycopg2), database_config)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)

# Disables passing `bytes` to txn.execute, c.f. #6186. If you do
Expand Down
8 changes: 5 additions & 3 deletions synapse/storage/engines/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
import sqlite3
import struct
import threading
from typing import TYPE_CHECKING, Any, List, Mapping, Optional
from typing import TYPE_CHECKING, Any, List, Mapping, Optional, cast

from synapse.storage.engines import BaseDatabaseEngine
from synapse.storage.types import Cursor
from synapse.storage.types import Cursor, DBAPI2Module

if TYPE_CHECKING:
from synapse.storage.database import LoggingDatabaseConnection


class Sqlite3Engine(BaseDatabaseEngine[sqlite3.Connection, sqlite3.Cursor]):
def __init__(self, database_config: Mapping[str, Any]):
super().__init__(sqlite3, database_config)
# Cast: mypy 1.0.0 doesn't seem to think that the module implements the protocol.
# AFAICS this is a false positive.
super().__init__(cast(DBAPI2Module, sqlite3), database_config)

database = database_config.get("args", {}).get("database")
self._is_in_memory = database in (
Expand Down