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

Commit e2b8a90

Browse files
Update mypy configuration: no_implicit_optional = True (#9742)
1 parent 4609e58 commit e2b8a90

File tree

10 files changed

+21
-11
lines changed

10 files changed

+21
-11
lines changed

changelog.d/9742.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Start linting mypy with `no_implicit_optional`.

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ show_traceback = True
88
mypy_path = stubs
99
warn_unreachable = True
1010
local_partial_types = True
11+
no_implicit_optional = True
1112

1213
# To find all folders that pass mypy you run:
1314
#

synapse/handlers/account_validity.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import logging
1919
from email.mime.multipart import MIMEMultipart
2020
from email.mime.text import MIMEText
21-
from typing import TYPE_CHECKING, List
21+
from typing import TYPE_CHECKING, List, Optional
2222

2323
from synapse.api.errors import StoreError, SynapseError
2424
from synapse.logging.context import make_deferred_yieldable
@@ -241,7 +241,10 @@ async def renew_account(self, renewal_token: str) -> bool:
241241
return True
242242

243243
async def renew_account_for_user(
244-
self, user_id: str, expiration_ts: int = None, email_sent: bool = False
244+
self,
245+
user_id: str,
246+
expiration_ts: Optional[int] = None,
247+
email_sent: bool = False,
245248
) -> int:
246249
"""Renews the account attached to a given user by pushing back the
247250
expiration date by the current validity period in the server's

synapse/handlers/e2e_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ async def _process_other_signatures(
10081008
return signature_list, failures
10091009

10101010
async def _get_e2e_cross_signing_verify_key(
1011-
self, user_id: str, key_type: str, from_user_id: str = None
1011+
self, user_id: str, key_type: str, from_user_id: Optional[str] = None
10121012
) -> Tuple[JsonDict, str, VerifyKey]:
10131013
"""Fetch locally or remotely query for a cross-signing public key.
10141014

synapse/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ async def put_json(
590590
uri: str,
591591
json_body: Any,
592592
args: Optional[QueryParams] = None,
593-
headers: RawHeaders = None,
593+
headers: Optional[RawHeaders] = None,
594594
) -> Any:
595595
"""Puts some json to the given URI.
596596

synapse/notifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ async def get_events_for(
548548
pagination_config: PaginationConfig,
549549
timeout: int,
550550
is_guest: bool = False,
551-
explicit_room_id: str = None,
551+
explicit_room_id: Optional[str] = None,
552552
) -> EventStreamResult:
553553
"""For the given user and rooms, return any new events for them. If
554554
there are no new events wait for up to `timeout` milliseconds for any

synapse/replication/tcp/redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ConstantProperty(Generic[T, V]):
6060

6161
constant = attr.ib() # type: V
6262

63-
def __get__(self, obj: Optional[T], objtype: Type[T] = None) -> V:
63+
def __get__(self, obj: Optional[T], objtype: Optional[Type[T]] = None) -> V:
6464
return self.constant
6565

6666
def __set__(self, obj: Optional[T], value: V):

synapse/storage/databases/main/group_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ async def add_user_to_group(
10271027
user_id: str,
10281028
is_admin: bool = False,
10291029
is_public: bool = True,
1030-
local_attestation: dict = None,
1031-
remote_attestation: dict = None,
1030+
local_attestation: Optional[dict] = None,
1031+
remote_attestation: Optional[dict] = None,
10321032
) -> None:
10331033
"""Add a user to the group server.
10341034

synapse/util/caches/deferred_cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ def eb(_fail):
283283
# we return a new Deferred which will be called before any subsequent observers.
284284
return observable.observe()
285285

286-
def prefill(self, key: KT, value: VT, callback: Callable[[], None] = None):
286+
def prefill(
287+
self, key: KT, value: VT, callback: Optional[Callable[[], None]] = None
288+
):
287289
callbacks = [callback] if callback else []
288290
self.cache.set(key, value, callbacks=callbacks)
289291

tests/rest/client/v2_alpha/test_auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
from typing import Union
16+
from typing import Optional, Union
1717

1818
from twisted.internet.defer import succeed
1919

@@ -74,7 +74,10 @@ def register(self, expected_response: int, body: JsonDict) -> FakeChannel:
7474
return channel
7575

7676
def recaptcha(
77-
self, session: str, expected_post_response: int, post_session: str = None
77+
self,
78+
session: str,
79+
expected_post_response: int,
80+
post_session: Optional[str] = None,
7881
) -> None:
7982
"""Get and respond to a fallback recaptcha. Returns the second request."""
8083
if post_session is None:

0 commit comments

Comments
 (0)