diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 1f37b57373..7e952f711a 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -27,14 +27,13 @@ from synapse.api.constants import ( JoinRules, PublicRoomsFilterFields, ) -from synapse.types import Requester from synapse.api.errors import ( Codes, HttpResponseException, RequestSendFailed, SynapseError, ) -from synapse.types import JsonDict, PublicRoom, ThirdPartyInstanceID +from synapse.types import JsonDict, ThirdPartyInstanceID from synapse.util.caches.descriptors import _CacheContext, cached from synapse.util.caches.response_cache import ResponseCache @@ -213,7 +212,7 @@ class RoomListHandler: response: JsonDict = {} num_results = len(results) - if limit is not None: + if limit is not None and probing_limit is not None: more_to_come = num_results >= probing_limit # Depending on direction we trim either the front or back. diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py index 16bd966efe..e6d04b9dec 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py @@ -122,7 +122,6 @@ from synapse.types import ( DomainSpecificString, JsonDict, JsonMapping, - PublicRoom, Requester, RoomAlias, StateMap, diff --git a/synapse/module_api/callbacks/public_rooms_callbacks.py b/synapse/module_api/callbacks/public_rooms_callbacks.py index 847becc89b..f12667d202 100644 --- a/synapse/module_api/callbacks/public_rooms_callbacks.py +++ b/synapse/module_api/callbacks/public_rooms_callbacks.py @@ -14,9 +14,9 @@ import logging from typing import Awaitable, Callable, Iterable, List, Optional, Tuple -from synapse.types import PublicRoom -import attr + +from synapse.types import PublicRoom logger = logging.getLogger(__name__) diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index 67613ab90e..ec9691a5ce 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -16,7 +16,6 @@ import logging from abc import abstractmethod from enum import Enum -from synapse.api.constants import HistoryVisibility from typing import ( TYPE_CHECKING, AbstractSet, @@ -39,6 +38,7 @@ from synapse.api.constants import ( Direction, EventContentFields, EventTypes, + HistoryVisibility, JoinRules, PublicRoomsFilterFields, ) @@ -543,7 +543,7 @@ class RoomWorkerStore(CacheInvalidationWorkerStore): # Filter out Nones – rather omit the field altogether for key in list(entry): - if entry[key] == None: + if entry[key] is None: del entry[key] return entry diff --git a/synapse/types/__init__.py b/synapse/types/__init__.py index c593299a14..71be9b523f 100644 --- a/synapse/types/__init__.py +++ b/synapse/types/__init__.py @@ -27,6 +27,7 @@ from typing import ( MutableMapping, NoReturn, Optional, + Required, Set, Tuple, Type, @@ -953,15 +954,15 @@ class UserInfo: is_shadow_banned: bool -class PublicRoom(TypedDict): - room_id: str +class PublicRoom(TypedDict, total=False): + room_id: Required[str] name: Optional[str] topic: Optional[str] - num_joined_members: int + num_joined_members: Required[int] canonical_alias: Optional[str] avatar_url: Optional[str] - world_readable: bool - guest_can_join: bool + world_readable: Required[bool] + guest_can_join: Required[bool] join_rule: Optional[str] room_type: Optional[str] diff --git a/tests/module_api/test_fetch_public_rooms.py b/tests/module_api/test_fetch_public_rooms.py index 1486fbfab9..0d77cf6f74 100644 --- a/tests/module_api/test_fetch_public_rooms.py +++ b/tests/module_api/test_fetch_public_rooms.py @@ -11,22 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from twisted.test.proto_helpers import MemoryReactor - from http import HTTPStatus from typing import ( - TYPE_CHECKING, - Callable, - Dict, - List, - Optional, - TypeVar, - Tuple, - cast, Iterable, + Optional, + Tuple, ) -from synapse.api.errors import SynapseError +from twisted.test.proto_helpers import MemoryReactor + from synapse.rest import admin, login, room from synapse.server import HomeServer from synapse.types import PublicRoom @@ -119,4 +112,4 @@ class FetchPublicRoomsTestCase(HomeserverTestCase): "GET", self.url + "?limit=1&since=" + channel.json_body["next_batch"] ) self.assertEqual(channel.code, HTTPStatus.OK, channel.result) - self.assertEquals(channel.json_body["chunk"][0]["num_joined_members"], 1) \ No newline at end of file + self.assertEquals(channel.json_body["chunk"][0]["num_joined_members"], 1)