types: Define UserDisplayRecipient type using TypedDict.

Since the display_recipients dictionaries corresponding to users are
always dictionaries with keys email, full_name, short_name, id,
is_mirror_dummy - instead of using the overly general Dict[str, Any]
type, we can define a UserDisplayRecipient type,
using an appropriate TypedDict.

The type definitions are moved from display_recipient.py to types.py, so
that they can be imported in models.py.

Appropriate type adjustments are made in various places in the code
where we operate on display_recipients.
This commit is contained in:
Mateusz Mandera
2019-08-18 00:24:46 +02:00
committed by Tim Abbott
parent c779bb1959
commit 3ba0a37a92
7 changed files with 33 additions and 18 deletions

View File

@@ -27,3 +27,7 @@ ExtendedFieldElement = Tuple[int, str, ExtendedValidator, Callable[[Any], Any],
UserFieldElement = Tuple[int, str, RealmUserValidator, Callable[[Any], Any], str]
ProfileFieldData = Dict[str, Union[Dict[str, str], str]]
UserDisplayRecipient = TypedDict('UserDisplayRecipient', {'email': str, 'full_name': str, 'short_name': str,
'id': int, 'is_mirror_dummy': bool})
DisplayRecipientCacheT = Union[str, List[UserDisplayRecipient]]