types: Fix declared type of custom profile field values.

None of the existing custom profile field types have the value as an
integer like declared in many places - nor is it a string like currently
decalred in types.py. The correct type is Union[str, List[int]]. Rather
than tracking this in so many places throughout the codebase, we add a
new ProfileDataElementValue type and insert it where appropriate.
This commit is contained in:
Mateusz Mandera
2021-09-21 16:52:15 +02:00
committed by Tim Abbott
parent 91ea21a3fc
commit cacff28578
8 changed files with 29 additions and 19 deletions

View File

@@ -76,6 +76,7 @@ from zerver.lib.types import (
LinkifierDict,
ProfileData,
ProfileDataElementBase,
ProfileDataElementValue,
RealmUserValidator,
UserFieldElement,
Validator,
@@ -3904,7 +3905,7 @@ class CustomProfileField(models.Model):
ALL_FIELD_TYPES = [*FIELD_TYPE_DATA, *SELECT_FIELD_TYPE_DATA, *USER_FIELD_TYPE_DATA]
FIELD_VALIDATORS: Dict[int, Validator[Union[int, str, List[int]]]] = {
FIELD_VALIDATORS: Dict[int, Validator[ProfileDataElementValue]] = {
item[0]: item[2] for item in FIELD_TYPE_DATA
}
FIELD_CONVERTERS: Dict[int, Callable[[Any], Any]] = {