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
Define StateMap as immutable and add a MutableStateMap type. #8183
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8bc1bc3
Define StateMap as immutable and add a MutableStateMap type.
clokep a7f2152
Use cast isntead of ignore.
clokep 8225e15
Fix typo.
clokep e195c5c
Merge remote-tracking branch 'origin/develop' into clokep/state-map
clokep a1168fa
Merge remote-tracking branch 'refs/remotes/origin/clokep/state-map' i…
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 type hints to `synapse.state`. |
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 |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
from synapse.api.errors import AuthError | ||
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS | ||
from synapse.events import EventBase | ||
from synapse.types import StateMap | ||
from synapse.types import MutableStateMap, StateMap | ||
from synapse.util import Clock | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -414,7 +414,7 @@ async def _iterative_auth_checks( | |
base_state: StateMap[str], | ||
event_map: Dict[str, EventBase], | ||
state_res_store: "synapse.state.StateResolutionStore", | ||
) -> StateMap[str]: | ||
) -> MutableStateMap[str]: | ||
"""Sequentially apply auth checks to each event in given list, updating the | ||
state as it goes along. | ||
|
||
|
@@ -430,7 +430,7 @@ async def _iterative_auth_checks( | |
Returns: | ||
Returns the final updated state | ||
""" | ||
resolved_state = base_state.copy() | ||
resolved_state = dict(base_state) | ||
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.
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. I agree — both do shallow copies. |
||
room_version_obj = KNOWN_ROOM_VERSIONS[room_version] | ||
|
||
for idx, event_id in enumerate(event_ids, start=1): | ||
|
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
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.
If there's something better to do here let me know. I think we could do it with temporary variables, but it would make the code harder to follow?
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.
cast
toMutableStateMap
might be more preferable,though I'd be concerned about taking something immutable, falsely declaring it as mutable and then passing it to a function taking the mutable variant (that function 'could' change in the future, if we're being general).
I'd say that you should be preferring to lock things down (take the prior mutable and say it is now immutable).
Not sure about the specific risk in this scenario though.
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.
That seems reasonable. I think it is OK to falsely declare it as mutable here, see a7f2152.