This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Require type hints in the handlers module #10831
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2b75539
Add return None to methods.
clokep 769119a
Update type hints for get_new_events.
clokep 5dc2708
Add missing type hints.
clokep c483526
Switch attrs to auto-attribs and finish types.
clokep d13af00
Add type hints to SSO errors.
clokep 9fe9275
Do not return empty results.
clokep aa3c57c
Add types to context managers.
clokep 3f2a56f
Fix type hints for password providers.
clokep 61e89c5
Fix-up type hints for federation handler.
clokep d304924
Update purge status to attrs.
clokep d819cfa
Require type hints for handlers.
clokep 0cc57db
Newsfragment
clokep 80dbc7b
Remove unused function.
clokep 18bc1c1
Merge remote-tracking branch 'origin/develop' into clokep/handler-types
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add missing type hints to handlers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
from typing import TYPE_CHECKING, Collection, Dict, List, Optional, Union | ||
from typing import TYPE_CHECKING, Collection, Dict, Iterable, List, Optional, Union | ||
|
||
from prometheus_client import Counter | ||
|
||
|
@@ -58,7 +58,7 @@ def __init__(self, hs: "HomeServer"): | |
self.current_max = 0 | ||
self.is_processing = False | ||
|
||
def notify_interested_services(self, max_token: RoomStreamToken): | ||
def notify_interested_services(self, max_token: RoomStreamToken) -> None: | ||
"""Notifies (pushes) all application services interested in this event. | ||
|
||
Pushing is done asynchronously, so this method won't block for any | ||
|
@@ -82,7 +82,7 @@ def notify_interested_services(self, max_token: RoomStreamToken): | |
self._notify_interested_services(max_token) | ||
|
||
@wrap_as_background_process("notify_interested_services") | ||
async def _notify_interested_services(self, max_token: RoomStreamToken): | ||
async def _notify_interested_services(self, max_token: RoomStreamToken) -> None: | ||
with Measure(self.clock, "notify_interested_services"): | ||
self.is_processing = True | ||
try: | ||
|
@@ -100,7 +100,7 @@ async def _notify_interested_services(self, max_token: RoomStreamToken): | |
for event in events: | ||
events_by_room.setdefault(event.room_id, []).append(event) | ||
|
||
async def handle_event(event): | ||
async def handle_event(event: EventBase) -> None: | ||
# Gather interested services | ||
services = await self._get_services_for_event(event) | ||
if len(services) == 0: | ||
|
@@ -116,9 +116,9 @@ async def handle_event(event): | |
|
||
if not self.started_scheduler: | ||
|
||
async def start_scheduler(): | ||
async def start_scheduler() -> None: | ||
try: | ||
return await self.scheduler.start() | ||
await self.scheduler.start() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
except Exception: | ||
logger.error("Application Services Failure") | ||
|
||
|
@@ -137,7 +137,7 @@ async def start_scheduler(): | |
"appservice_sender" | ||
).observe((now - ts) / 1000) | ||
|
||
async def handle_room_events(events): | ||
async def handle_room_events(events: Iterable[EventBase]) -> None: | ||
for event in events: | ||
await handle_event(event) | ||
|
||
|
@@ -184,7 +184,7 @@ def notify_interested_services_ephemeral( | |
stream_key: str, | ||
new_token: Optional[int], | ||
users: Optional[Collection[Union[str, UserID]]] = None, | ||
): | ||
) -> None: | ||
"""This is called by the notifier in the background | ||
when a ephemeral event handled by the homeserver. | ||
|
||
|
@@ -226,7 +226,7 @@ async def _notify_interested_services_ephemeral( | |
stream_key: str, | ||
new_token: Optional[int], | ||
users: Collection[Union[str, UserID]], | ||
): | ||
) -> None: | ||
logger.debug("Checking interested services for %s" % (stream_key)) | ||
with Measure(self.clock, "notify_interested_services_ephemeral"): | ||
for service in services: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,20 +34,20 @@ | |
class CasError(Exception): | ||
"""Used to catch errors when validating the CAS ticket.""" | ||
|
||
def __init__(self, error, error_description=None): | ||
def __init__(self, error: str, error_description: Optional[str] = None): | ||
self.error = error | ||
self.error_description = error_description | ||
|
||
def __str__(self): | ||
def __str__(self) -> str: | ||
if self.error_description: | ||
return f"{self.error}: {self.error_description}" | ||
return self.error | ||
|
||
|
||
@attr.s(slots=True, frozen=True) | ||
@attr.s(slots=True, frozen=True, auto_attribs=True) | ||
class CasResponse: | ||
username = attr.ib(type=str) | ||
attributes = attr.ib(type=Dict[str, List[Optional[str]]]) | ||
username: str | ||
attributes: Dict[str, List[Optional[str]]] | ||
|
||
|
||
class CasHandler: | ||
|
@@ -133,11 +133,9 @@ async def _validate_ticket( | |
body = pde.response | ||
except HttpResponseException as e: | ||
description = ( | ||
( | ||
'Authorization server responded with a "{status}" error ' | ||
"while exchanging the authorization code." | ||
).format(status=e.code), | ||
) | ||
'Authorization server responded with a "{status}" error ' | ||
"while exchanging the authorization code." | ||
).format(status=e.code) | ||
Comment on lines
135
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a real bug, it was passing a tuple instead of a string. |
||
raise CasError("server_error", description) from e | ||
|
||
return self._parse_cas_response(body) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this
kwargs
for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
get_new_events
generally takes some random arguments which most things don't care about. I did verify that there are other arguments going into this call, I'll double check if we can tighten this up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be cleaned up, but I'd prefer to do it in a separate PR if that's OK!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I resolved the other threads about this to keep the conversation in one spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, take this to another PR if you prefer.