-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix type annotation in get_stream_id_for_event_txn
#12470
fix type annotation in get_stream_id_for_event_txn
#12470
Conversation
get_stream_id_for_event_txn
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.
Hi @gautamgiri-dev. Thanks for taking this on. There are some problems I've outlined below. Can you also please run the linter script? See https://matrix-org.github.io/synapse/develop/code_style.html for instructions.
@overload | ||
@classmethod | ||
def simple_select_one_onecol_txn( | ||
cls, | ||
txn: LoggingTransaction, | ||
table: str, | ||
keyvalues: Dict[str, Any], | ||
retcol: str, | ||
allow_none: bool = False, | ||
) -> Optional[int]: | ||
ret = cls.simple_select_one_onecol_txn(cls, txn, table=table, keyvalues=keyvalues, retcol=retcol, allow_none=allow_none) | ||
if ret: | ||
return int(ret) | ||
return ret |
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.
This doesn't look right --- @overloads
should not have an implementation; they should be for type hints only. See https://mypy.readthedocs.io/en/stable/more_types.html#function-overloading for more details.
Furthermore this is a generic function and there is no particular reason this should return an int. Additionally, the call to cls.simple_select_one_onecol_txn
would infinitely recurse.
Can you explain your thinking here? What error was this attempting to address?
@@ -191,7 +191,7 @@ def _get_unread_counts_by_receipt_txn( | |||
stream_ordering = None | |||
|
|||
if last_read_event_id is not None: | |||
stream_ordering = self.get_stream_id_for_event_txn( # type: ignore[attr-defined] | |||
stream_ordering = self.get_stream_id_for_event_txn( |
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.
As I mentioned in #12437, for this to have any chance of working we need to change the class EventPushActionsWorkerStore
to inherit from StreamWorkerStore
: see my point 2 there.
Note that this may end up causing runtime failures if we run into MRO problems. If that's the case, CI will detect this.
I think this got done in #12716. |
Fixes: #12437
StreamWorkerStore.get_stream_id_for_event_txn
now has return typeOptional[int]
which is consistent with theNoneType
whenallow_none=True
.Signed-off-by: Gautam Kumar Giri personal.gautamgiri@gmail.com
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)