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
Correct check_username_for_spam
annotations and docs
#12246
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7fe7b42
Formally type the UserProfile in user searches
c391880
Update docs
ba3856f
Changelog
4a65178
Use Sean's colon
d54b35b
import TypedDict from typing extensions
8a1eae8
export UserProfile in synapse.module_api
ada0b32
import TypedDict from typing_extensions, part 2
5747d69
linter script
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 @@ | ||
Correct `check_username_for_spam` annotations and docs. |
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
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.
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)