0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-06-14 16:48:18 +02:00

Update mypy configuration: no_implicit_optional = True (#9742)

This commit is contained in:
Jonathan de Jong 2021-04-05 15:10:18 +02:00 committed by GitHub
parent 4609e58970
commit e2b8a90897
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 11 deletions

1
changelog.d/9742.misc Normal file
View file

@ -0,0 +1 @@
Start linting mypy with `no_implicit_optional`.

View file

@ -8,6 +8,7 @@ show_traceback = True
mypy_path = stubs mypy_path = stubs
warn_unreachable = True warn_unreachable = True
local_partial_types = True local_partial_types = True
no_implicit_optional = True
# To find all folders that pass mypy you run: # To find all folders that pass mypy you run:
# #

View file

@ -18,7 +18,7 @@ import email.utils
import logging import logging
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from typing import TYPE_CHECKING, List from typing import TYPE_CHECKING, List, Optional
from synapse.api.errors import StoreError, SynapseError from synapse.api.errors import StoreError, SynapseError
from synapse.logging.context import make_deferred_yieldable from synapse.logging.context import make_deferred_yieldable
@ -241,7 +241,10 @@ class AccountValidityHandler:
return True return True
async def renew_account_for_user( async def renew_account_for_user(
self, user_id: str, expiration_ts: int = None, email_sent: bool = False self,
user_id: str,
expiration_ts: Optional[int] = None,
email_sent: bool = False,
) -> int: ) -> int:
"""Renews the account attached to a given user by pushing back the """Renews the account attached to a given user by pushing back the
expiration date by the current validity period in the server's expiration date by the current validity period in the server's

View file

@ -1008,7 +1008,7 @@ class E2eKeysHandler:
return signature_list, failures return signature_list, failures
async def _get_e2e_cross_signing_verify_key( async def _get_e2e_cross_signing_verify_key(
self, user_id: str, key_type: str, from_user_id: str = None self, user_id: str, key_type: str, from_user_id: Optional[str] = None
) -> Tuple[JsonDict, str, VerifyKey]: ) -> Tuple[JsonDict, str, VerifyKey]:
"""Fetch locally or remotely query for a cross-signing public key. """Fetch locally or remotely query for a cross-signing public key.

View file

@ -590,7 +590,7 @@ class SimpleHttpClient:
uri: str, uri: str,
json_body: Any, json_body: Any,
args: Optional[QueryParams] = None, args: Optional[QueryParams] = None,
headers: RawHeaders = None, headers: Optional[RawHeaders] = None,
) -> Any: ) -> Any:
"""Puts some json to the given URI. """Puts some json to the given URI.

View file

@ -548,7 +548,7 @@ class Notifier:
pagination_config: PaginationConfig, pagination_config: PaginationConfig,
timeout: int, timeout: int,
is_guest: bool = False, is_guest: bool = False,
explicit_room_id: str = None, explicit_room_id: Optional[str] = None,
) -> EventStreamResult: ) -> EventStreamResult:
"""For the given user and rooms, return any new events for them. If """For the given user and rooms, return any new events for them. If
there are no new events wait for up to `timeout` milliseconds for any there are no new events wait for up to `timeout` milliseconds for any

View file

@ -60,7 +60,7 @@ class ConstantProperty(Generic[T, V]):
constant = attr.ib() # type: V constant = attr.ib() # type: V
def __get__(self, obj: Optional[T], objtype: Type[T] = None) -> V: def __get__(self, obj: Optional[T], objtype: Optional[Type[T]] = None) -> V:
return self.constant return self.constant
def __set__(self, obj: Optional[T], value: V): def __set__(self, obj: Optional[T], value: V):

View file

@ -1027,8 +1027,8 @@ class GroupServerStore(GroupServerWorkerStore):
user_id: str, user_id: str,
is_admin: bool = False, is_admin: bool = False,
is_public: bool = True, is_public: bool = True,
local_attestation: dict = None, local_attestation: Optional[dict] = None,
remote_attestation: dict = None, remote_attestation: Optional[dict] = None,
) -> None: ) -> None:
"""Add a user to the group server. """Add a user to the group server.

View file

@ -283,7 +283,9 @@ class DeferredCache(Generic[KT, VT]):
# we return a new Deferred which will be called before any subsequent observers. # we return a new Deferred which will be called before any subsequent observers.
return observable.observe() return observable.observe()
def prefill(self, key: KT, value: VT, callback: Callable[[], None] = None): def prefill(
self, key: KT, value: VT, callback: Optional[Callable[[], None]] = None
):
callbacks = [callback] if callback else [] callbacks = [callback] if callback else []
self.cache.set(key, value, callbacks=callbacks) self.cache.set(key, value, callbacks=callbacks)

View file

@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from typing import Union from typing import Optional, Union
from twisted.internet.defer import succeed from twisted.internet.defer import succeed
@ -74,7 +74,10 @@ class FallbackAuthTests(unittest.HomeserverTestCase):
return channel return channel
def recaptcha( def recaptcha(
self, session: str, expected_post_response: int, post_session: str = None self,
session: str,
expected_post_response: int,
post_session: Optional[str] = None,
) -> None: ) -> None:
"""Get and respond to a fallback recaptcha. Returns the second request.""" """Get and respond to a fallback recaptcha. Returns the second request."""
if post_session is None: if post_session is None: