This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
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.
Correct
check_username_for_spam
annotations and docs #12246Correct
check_username_for_spam
annotations and docs #12246Changes from 3 commits
7fe7b42
c391880
ba3856f
4a65178
d54b35b
8a1eae8
ada0b32
5747d69
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
It's worth noting that
Mapping
s aren't necessarily JSON-serialisable, unless they're reallydict
s orfrozendict
s. Essentially when we useJsonMapping
, we're pinky promising that it's really a(frozen)dict
.The same kind of thing applies to
JsonSerializable
below I guess.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 wasn't 100% sold on this either. I wanted to see if there was a way to make more use of
TypedDicts
without having to cast those back toJsonDicts
everywhere. Maybe I could just make the return type of this functionSearchResult
? That feels a bit off though---it's exposing a type from storage.databases.main in rest.client.synapse/synapse/rest/client/user_directory.py
Line 41 in 7fe7b42
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 do think there is a case for having a
JsonMapping
type, to signal that functions aren't allowed to modify the contents of a dict. Especially around caches.I'm not opposed to making the return type some sort of
TypedDict
. I think we really ought to have a file somewhere full ofTypedDict
definitions that come from the spec, since that's the source of truth for the return type here (and not the database layer).In any case I'm happy with the
JsonMapping
as is.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 broadly sympathise, but I don't think that'd be fool proof: e.g. given
d: JsonMapping = {"a": [1,2,3]}
I thinkd["a"].append(4)
would still type check?I like the sound of this; e.g.
synapse.types.spec.UserDirectorySearchResult
. I guess the dream would be to automatically generate such a file from the openapi definition in the spec.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.
True! Unless we manage to define
JsonMapping = Mapping[str, ImmutableJsonSerializable]
recursively, which mypy won't let us do. (grumble grumble this would be possible in typescript)