Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .ci/scripts/auditwheel_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import argparse
import os
import subprocess
from typing import Optional
from zipfile import ZipFile

from packaging.tags import Tag
Expand Down Expand Up @@ -80,7 +79,7 @@ def cpython(wheel_file: str, name: str, version: Version, tag: Tag) -> str:
return new_wheel_file


def main(wheel_file: str, dest_dir: str, archs: Optional[str]) -> None:
def main(wheel_file: str, dest_dir: str, archs: str | None) -> None:
"""Entry point"""

# Parse the wheel file name into its parts. Note that `parse_wheel_filename`
Expand Down
1 change: 1 addition & 0 deletions changelog.d/19111.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write union types as `X | Y` where possible, as per PEP 604, added in Python 3.10.
3 changes: 1 addition & 2 deletions contrib/cmdclient/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import time
import urllib
from http import TwistedHttpClient
from typing import Optional

import urlparse
from signedjson.key import NACL_ED25519, decode_verify_key_bytes
Expand Down Expand Up @@ -726,7 +725,7 @@ def _run_and_pprint(
method,
path,
data=None,
query_params: Optional[dict] = None,
query_params: dict | None = None,
alt_text=None,
):
"""Runs an HTTP request and pretty prints the output.
Expand Down
9 changes: 4 additions & 5 deletions contrib/cmdclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import json
import urllib
from pprint import pformat
from typing import Optional

from twisted.internet import defer, reactor
from twisted.web.client import Agent, readBody
Expand Down Expand Up @@ -90,7 +89,7 @@ def get_json(self, url, args=None):
body = yield readBody(response)
return json.loads(body)

def _create_put_request(self, url, json_data, headers_dict: Optional[dict] = None):
def _create_put_request(self, url, json_data, headers_dict: dict | None = None):
"""Wrapper of _create_request to issue a PUT request"""
headers_dict = headers_dict or {}

Expand All @@ -101,7 +100,7 @@ def _create_put_request(self, url, json_data, headers_dict: Optional[dict] = Non
"PUT", url, producer=_JsonProducer(json_data), headers_dict=headers_dict
)

def _create_get_request(self, url, headers_dict: Optional[dict] = None):
def _create_get_request(self, url, headers_dict: dict | None = None):
"""Wrapper of _create_request to issue a GET request"""
return self._create_request("GET", url, headers_dict=headers_dict or {})

Expand All @@ -113,7 +112,7 @@ def do_request(
data=None,
qparams=None,
jsonreq=True,
headers: Optional[dict] = None,
headers: dict | None = None,
):
headers = headers or {}

Expand All @@ -138,7 +137,7 @@ def do_request(

@defer.inlineCallbacks
def _create_request(
self, method, url, producer=None, headers_dict: Optional[dict] = None
self, method, url, producer=None, headers_dict: dict | None = None
):
"""Creates and sends a request to the given url"""
headers_dict = headers_dict or {}
Expand Down
5 changes: 2 additions & 3 deletions docker/configure_workers_and_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
Mapping,
MutableMapping,
NoReturn,
Optional,
SupportsIndex,
)

Expand Down Expand Up @@ -468,7 +467,7 @@ def add_worker_roles_to_shared_config(


def merge_worker_template_configs(
existing_dict: Optional[dict[str, Any]],
existing_dict: dict[str, Any] | None,
to_be_merged_dict: dict[str, Any],
) -> dict[str, Any]:
"""When given an existing dict of worker template configuration consisting with both
Expand Down Expand Up @@ -1026,7 +1025,7 @@ def generate_worker_log_config(
Returns: the path to the generated file
"""
# Check whether we should write worker logs to disk, in addition to the console
extra_log_template_args: dict[str, Optional[str]] = {}
extra_log_template_args: dict[str, str | None] = {}
if environ.get("SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK"):
extra_log_template_args["LOG_FILE_PATH"] = f"{data_dir}/logs/{worker_name}.log"

Expand Down
6 changes: 3 additions & 3 deletions docker/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import platform
import subprocess
import sys
from typing import Any, Mapping, MutableMapping, NoReturn, Optional
from typing import Any, Mapping, MutableMapping, NoReturn

import jinja2

Expand Down Expand Up @@ -50,7 +50,7 @@ def generate_config_from_template(
config_dir: str,
config_path: str,
os_environ: Mapping[str, str],
ownership: Optional[str],
ownership: str | None,
) -> None:
"""Generate a homeserver.yaml from environment variables

Expand Down Expand Up @@ -147,7 +147,7 @@ def generate_config_from_template(
subprocess.run(args, check=True)


def run_generate_config(environ: Mapping[str, str], ownership: Optional[str]) -> None:
def run_generate_config(environ: Mapping[str, str], ownership: str | None) -> None:
"""Run synapse with a --generate-config param to generate a template config file

Args:
Expand Down
6 changes: 3 additions & 3 deletions docs/development/synapse_architecture/cancellation.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ logcontext is not finished before the `async` processing completes.

**Bad**:
```python
cache: Optional[ObservableDeferred[None]] = None
cache: ObservableDeferred[None] | None = None

async def do_something_else(
to_resolve: Deferred[None]
Expand All @@ -326,7 +326,7 @@ with LoggingContext("request-1"):

**Good**:
```python
cache: Optional[ObservableDeferred[None]] = None
cache: ObservableDeferred[None] | None = None

async def do_something_else(
to_resolve: Deferred[None]
Expand Down Expand Up @@ -358,7 +358,7 @@ with LoggingContext("request-1"):

**OK**:
```python
cache: Optional[ObservableDeferred[None]] = None
cache: ObservableDeferred[None] | None = None

async def do_something_else(
to_resolve: Deferred[None]
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/account_data_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _First introduced in Synapse v1.57.0_
```python
async def on_account_data_updated(
user_id: str,
room_id: Optional[str],
room_id: str | None,
account_data_type: str,
content: "synapse.module_api.JsonDict",
) -> None:
Expand Down Expand Up @@ -82,7 +82,7 @@ class CustomAccountDataModule:
async def log_new_account_data(
self,
user_id: str,
room_id: Optional[str],
room_id: str | None,
account_data_type: str,
content: JsonDict,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/account_validity_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The available account validity callbacks are:
_First introduced in Synapse v1.39.0_

```python
async def is_user_expired(user: str) -> Optional[bool]
async def is_user_expired(user: str) -> bool | None
```

Called when processing any authenticated request (except for logout requests). The module
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/media_repository_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The available media repository callbacks are:
_First introduced in Synapse v1.132.0_

```python
async def get_media_config_for_user(user_id: str) -> Optional[JsonDict]
async def get_media_config_for_user(user_id: str) -> JsonDict | None
```

**<span style="color:red">
Expand Down Expand Up @@ -70,7 +70,7 @@ implementations of this callback.
_First introduced in Synapse v1.139.0_

```python
async def get_media_upload_limits_for_user(user_id: str, size: int) -> Optional[List[synapse.module_api.MediaUploadLimit]]
async def get_media_upload_limits_for_user(user_id: str, size: int) -> list[synapse.module_api.MediaUploadLimit] | None
```

**<span style="color:red">
Expand Down
34 changes: 7 additions & 27 deletions docs/modules/password_auth_provider_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ async def check_auth(
user: str,
login_type: str,
login_dict: "synapse.module_api.JsonDict",
) -> Optional[
Tuple[
str,
Optional[Callable[["synapse.module_api.LoginResponse"], Awaitable[None]]]
]
]
) -> tuple[str, Callable[["synapse.module_api.LoginResponse"], Awaitable[None]] | None] | None
```

The login type and field names should be provided by the user in the
Expand Down Expand Up @@ -67,12 +62,7 @@ async def check_3pid_auth(
medium: str,
address: str,
password: str,
) -> Optional[
Tuple[
str,
Optional[Callable[["synapse.module_api.LoginResponse"], Awaitable[None]]]
]
]
) -> tuple[str, Callable[["synapse.module_api.LoginResponse"], Awaitable[None]] | None]
```

Called when a user attempts to register or log in with a third party identifier,
Expand All @@ -98,7 +88,7 @@ _First introduced in Synapse v1.46.0_
```python
async def on_logged_out(
user_id: str,
device_id: Optional[str],
device_id: str | None,
access_token: str
) -> None
```
Expand All @@ -119,7 +109,7 @@ _First introduced in Synapse v1.52.0_
async def get_username_for_registration(
uia_results: Dict[str, Any],
params: Dict[str, Any],
) -> Optional[str]
) -> str | None
```

Called when registering a new user. The module can return a username to set for the user
Expand Down Expand Up @@ -180,7 +170,7 @@ _First introduced in Synapse v1.54.0_
async def get_displayname_for_registration(
uia_results: Dict[str, Any],
params: Dict[str, Any],
) -> Optional[str]
) -> str | None
```

Called when registering a new user. The module can return a display name to set for the
Expand Down Expand Up @@ -259,12 +249,7 @@ class MyAuthProvider:
username: str,
login_type: str,
login_dict: "synapse.module_api.JsonDict",
) -> Optional[
Tuple[
str,
Optional[Callable[["synapse.module_api.LoginResponse"], Awaitable[None]]],
]
]:
) -> tuple[str, Callable[["synapse.module_api.LoginResponse"], Awaitable[None]] | None] | None:
if login_type != "my.login_type":
return None

Expand All @@ -276,12 +261,7 @@ class MyAuthProvider:
username: str,
login_type: str,
login_dict: "synapse.module_api.JsonDict",
) -> Optional[
Tuple[
str,
Optional[Callable[["synapse.module_api.LoginResponse"], Awaitable[None]]],
]
]:
) -> tuple[str, Callable[["synapse.module_api.LoginResponse"], Awaitable[None]] | None] | None:
if login_type != "m.login.password":
return None

Expand Down
10 changes: 5 additions & 5 deletions docs/modules/presence_router_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _First introduced in Synapse v1.42.0_
```python
async def get_users_for_states(
state_updates: Iterable["synapse.api.UserPresenceState"],
) -> Dict[str, Set["synapse.api.UserPresenceState"]]
) -> dict[str, set["synapse.api.UserPresenceState"]]
```
**Requires** `get_interested_users` to also be registered

Expand All @@ -45,7 +45,7 @@ _First introduced in Synapse v1.42.0_
```python
async def get_interested_users(
user_id: str
) -> Union[Set[str], "synapse.module_api.PRESENCE_ALL_USERS"]
) -> set[str] | "synapse.module_api.PRESENCE_ALL_USERS"
```
**Requires** `get_users_for_states` to also be registered

Expand Down Expand Up @@ -73,7 +73,7 @@ that `@alice:example.org` receives all presence updates from `@bob:example.com`
`@charlie:somewhere.org`, regardless of whether Alice shares a room with any of them.

```python
from typing import Dict, Iterable, Set, Union
from typing import Iterable

from synapse.module_api import ModuleApi

Expand All @@ -90,7 +90,7 @@ class CustomPresenceRouter:
async def get_users_for_states(
self,
state_updates: Iterable["synapse.api.UserPresenceState"],
) -> Dict[str, Set["synapse.api.UserPresenceState"]]:
) -> dict[str, set["synapse.api.UserPresenceState"]]:
res = {}
for update in state_updates:
if (
Expand All @@ -104,7 +104,7 @@ class CustomPresenceRouter:
async def get_interested_users(
self,
user_id: str,
) -> Union[Set[str], "synapse.module_api.PRESENCE_ALL_USERS"]:
) -> set[str] | "synapse.module_api.PRESENCE_ALL_USERS":
if user_id == "@alice:example.com":
return {"@bob:example.com", "@charlie:somewhere.org"}

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ratelimit_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The available ratelimit callbacks are:
_First introduced in Synapse v1.132.0_

```python
async def get_ratelimit_override_for_user(user: str, limiter_name: str) -> Optional[synapse.module_api.RatelimitOverride]
async def get_ratelimit_override_for_user(user: str, limiter_name: str) -> synapse.module_api.RatelimitOverride | None
```

**<span style="color:red">
Expand Down
20 changes: 10 additions & 10 deletions docs/modules/spam_checker_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ search results; otherwise return `False`.
The profile is represented as a dictionary with the following keys:

* `user_id: str`. The Matrix ID for this user.
* `display_name: Optional[str]`. The user's display name, or `None` if this user
* `display_name: str | None`. The user's display name, or `None` if this user
has not set a display name.
* `avatar_url: Optional[str]`. The `mxc://` URL to the user's avatar, or `None`
* `avatar_url: str | None`. The `mxc://` URL to the user's avatar, or `None`
if this user has not set an avatar.

The module is given a copy of the original dictionary, so modifying it from within the
Expand All @@ -352,10 +352,10 @@ _First introduced in Synapse v1.37.0_

```python
async def check_registration_for_spam(
email_threepid: Optional[dict],
username: Optional[str],
email_threepid: dict | None,
username: str | None,
request_info: Collection[Tuple[str, str]],
auth_provider_id: Optional[str] = None,
auth_provider_id: str | None = None,
) -> "synapse.spam_checker_api.RegistrationBehaviour"
```

Expand Down Expand Up @@ -438,10 +438,10 @@ _First introduced in Synapse v1.87.0_
```python
async def check_login_for_spam(
user_id: str,
device_id: Optional[str],
initial_display_name: Optional[str],
request_info: Collection[Tuple[Optional[str], str]],
auth_provider_id: Optional[str] = None,
device_id: str | None,
initial_display_name: str | None,
request_info: Collection[tuple[str | None, str]],
auth_provider_id: str | None = None,
) -> Union["synapse.module_api.NOT_SPAM", "synapse.module_api.errors.Codes"]
```

Expand Down Expand Up @@ -509,7 +509,7 @@ class ListSpamChecker:
resource=IsUserEvilResource(config),
)

async def check_event_for_spam(self, event: "synapse.events.EventBase") -> Union[Literal["NOT_SPAM"], Codes]:
async def check_event_for_spam(self, event: "synapse.events.EventBase") -> Literal["NOT_SPAM"] | Codes:
if event.sender in self.evil_users:
return Codes.FORBIDDEN
else:
Expand Down
Loading
Loading