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
Consistently use collections.abc.Mapping to match frozendict. #12564
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 @@ | ||
Consistently check if an object is a `frozendict`. |
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,11 +12,10 @@ | |
# 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. | ||
import collections.abc | ||
import logging | ||
from typing import TYPE_CHECKING, Collection, Dict, Iterable, Optional, Set, Tuple | ||
|
||
from frozendict import frozendict | ||
|
||
from synapse.api.constants import EventTypes, Membership | ||
from synapse.api.errors import NotFoundError, UnsupportedRoomVersionError | ||
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion | ||
|
@@ -160,7 +159,7 @@ async def get_room_predecessor(self, room_id: str) -> Optional[JsonMapping]: | |
predecessor = create_event.content.get("predecessor", None) | ||
|
||
# Ensure the key is a dictionary | ||
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. Not sure if this comment could now be confusing in the future? |
||
if not isinstance(predecessor, (dict, frozendict)): | ||
if not isinstance(predecessor, collections.abc.Mapping): | ||
return None | ||
|
||
# The keys must be strings since the data is JSON. | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
# 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. | ||
import collections.abc | ||
from typing import Any | ||
|
||
from frozendict import frozendict | ||
|
@@ -35,7 +36,7 @@ def freeze(o: Any) -> Any: | |
|
||
|
||
def unfreeze(o: Any) -> Any: | ||
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 note that:
Judging from where we use it, it looks like this is only used to unfreeze event content rather than a generic unfreeze function. 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 don't believe it is meant to be a generic |
||
if isinstance(o, (dict, frozendict)): | ||
if isinstance(o, collections.abc.Mapping): | ||
return {k: unfreeze(v) for k, v in o.items()} | ||
|
||
if isinstance(o, (bytes, str)): | ||
|
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.
This one is slightly different, but I didn't see why it also shouldn't use
isinstance
?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 guess this would reject
sub_dict[sub_fields]
which were instances of a class that inherits from either dict or frozendict. I don't think we have a particularly good reason to do that 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.
This should all be data from JSON, so I can't see how we would get anything besides
dict
orfrozendict
.The code is from 2016 (70a2157 and 6d4e6d4) so I think it just didn't use
isinstance(...)
.