Skip to content

Commit df24e0f

Browse files
Fix support for older versions of zope-interface (#19274)
Fixes #19269 Versions of zope-interface from RHEL, Ubuntu LTS 22 & 24 and OpenSuse don't support the new python union `X | Y` syntax for interfaces. This PR partially reverts the change over to fully use the new syntax, adds a minimum supported version of zope-interface to Synapse's dependency list, and removes the linter auto-upgrades which prefer the newer syntax. ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [X] Pull request is based on the develop branch * [X] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [X] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --------- Co-authored-by: Andrew Morgan <[email protected]>
1 parent 048629d commit df24e0f

25 files changed

+65
-56
lines changed

changelog.d/19274.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug introduced in 1.143.0 that broke support for versions of `zope-interface` older than 6.2.

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ dependencies = [
109109
"pyrsistent>=0.18.0", # via jsonschema
110110
"requests>=2.16.0", # 2.16.0+ no longer vendors urllib3, avoiding Python 3.10+ incompatibility
111111
"urllib3>=1.26.5", # via treq; 1.26.5 fixes Python 3.10+ collections.abc compatibility
112-
"zope-interface>=6.2", # via twisted
112+
# 5.2 is the current version in Debian oldstable. If we don't care to support that, then 5.4 is
113+
# the minimum version from Ubuntu 22.04 and RHEL 9. (as of 2025-12)
114+
# When bumping this version to 6.2 or above, refer to https://github.com/element-hq/synapse/pull/19274
115+
# for details of Synapse improvements that may be unlocked. Particularly around the use of `|`
116+
# syntax with zope interface types.
117+
"zope-interface>=5.2", # via twisted
113118
]
114119

115120
[project.optional-dependencies]
@@ -383,15 +388,10 @@ select = [
383388
"G",
384389
# pyupgrade
385390
"UP006",
386-
"UP007",
387-
"UP045",
388391
]
389392
extend-safe-fixes = [
390393
# pyupgrade rules compatible with Python >= 3.9
391394
"UP006",
392-
"UP007",
393-
# pyupgrade rules compatible with Python >= 3.10
394-
"UP045",
395395
# Allow ruff to automatically fix trailing spaces within a multi-line string/comment.
396396
"W293"
397397
]

synapse/app/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
Awaitable,
3737
Callable,
3838
NoReturn,
39+
Optional,
3940
cast,
4041
)
4142
from wsgiref.simple_server import WSGIServer
@@ -455,7 +456,7 @@ def listen_http(
455456
root_resource: Resource,
456457
version_string: str,
457458
max_request_body_size: int,
458-
context_factory: IOpenSSLContextFactory | None,
459+
context_factory: Optional[IOpenSSLContextFactory],
459460
reactor: ISynapseReactor = reactor,
460461
) -> list[Port]:
461462
"""

synapse/app/admin_cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import os
2525
import sys
2626
import tempfile
27-
from typing import Mapping, Sequence
27+
from typing import Mapping, Optional, Sequence
2828

2929
from twisted.internet import defer, task
3030

@@ -291,7 +291,7 @@ def load_config(argv_options: list[str]) -> tuple[HomeServerConfig, argparse.Nam
291291

292292
def create_homeserver(
293293
config: HomeServerConfig,
294-
reactor: ISynapseReactor | None = None,
294+
reactor: Optional[ISynapseReactor] = None,
295295
) -> AdminCmdServer:
296296
"""
297297
Create a homeserver instance for the Synapse admin command process.

synapse/app/generic_worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#
2222
import logging
2323
import sys
24+
from typing import Optional
2425

2526
from twisted.web.resource import Resource
2627

@@ -335,7 +336,7 @@ def load_config(argv_options: list[str]) -> HomeServerConfig:
335336

336337
def create_homeserver(
337338
config: HomeServerConfig,
338-
reactor: ISynapseReactor | None = None,
339+
reactor: Optional[ISynapseReactor] = None,
339340
) -> GenericWorkerServer:
340341
"""
341342
Create a homeserver instance for the Synapse worker process.

synapse/app/homeserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import logging
2323
import os
2424
import sys
25-
from typing import Iterable
25+
from typing import Iterable, Optional
2626

2727
from twisted.internet.tcp import Port
2828
from twisted.web.resource import EncodingResourceWrapper, Resource
@@ -350,7 +350,7 @@ def load_or_generate_config(argv_options: list[str]) -> HomeServerConfig:
350350

351351
def create_homeserver(
352352
config: HomeServerConfig,
353-
reactor: ISynapseReactor | None = None,
353+
reactor: Optional[ISynapseReactor] = None,
354354
) -> SynapseHomeServer:
355355
"""
356356
Create a homeserver instance for the Synapse main process.

synapse/handlers/delayed_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414

1515
import logging
16-
from typing import TYPE_CHECKING
16+
from typing import TYPE_CHECKING, Optional
1717

1818
from twisted.internet.interfaces import IDelayedCall
1919

@@ -74,7 +74,7 @@ def __init__(self, hs: "HomeServer"):
7474
cfg=self._config.ratelimiting.rc_delayed_event_mgmt,
7575
)
7676

77-
self._next_delayed_event_call: IDelayedCall | None = None
77+
self._next_delayed_event_call: Optional[IDelayedCall] = None
7878

7979
# The current position in the current_state_delta stream
8080
self._event_pos: int | None = None

synapse/handlers/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import logging
2323
import random
2424
from http import HTTPStatus
25-
from typing import TYPE_CHECKING, Any, Mapping, Sequence
25+
from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence
2626

2727
from canonicaljson import encode_canonical_json
2828

@@ -111,7 +111,7 @@ def __init__(self, hs: "HomeServer"):
111111

112112
# The scheduled call to self._expire_event. None if no call is currently
113113
# scheduled.
114-
self._scheduled_expiry: IDelayedCall | None = None
114+
self._scheduled_expiry: Optional[IDelayedCall] = None
115115

116116
if not hs.config.worker.worker_app:
117117
self.hs.run_as_background_process(

synapse/handlers/user_directory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import logging
2323
from http import HTTPStatus
24-
from typing import TYPE_CHECKING
24+
from typing import TYPE_CHECKING, Optional
2525

2626
from twisted.internet.interfaces import IDelayedCall
2727

@@ -125,7 +125,7 @@ def __init__(self, hs: "HomeServer"):
125125
# Guard to ensure we only have one process for refreshing remote profiles
126126
self._is_refreshing_remote_profiles = False
127127
# Handle to cancel the `call_later` of `kick_off_remote_profile_refresh_process`
128-
self._refresh_remote_profiles_call_later: IDelayedCall | None = None
128+
self._refresh_remote_profiles_call_later: Optional[IDelayedCall] = None
129129

130130
# Guard to ensure we only have one process for refreshing remote profiles
131131
# for the given servers.

0 commit comments

Comments
 (0)