Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Revert to Type[Model] to keep type variable constrained; add type i…
Browse files Browse the repository at this point in the history
…gnores to work around mypy deficiency
  • Loading branch information
reivilibre committed Jul 5, 2023
1 parent 85eba85 commit 4c9de6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions synapse/config/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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.
from typing import Any, Dict, TypeVar
from typing import Any, Dict, TypeVar, Type

import jsonschema
from pydantic import BaseModel, ValidationError, parse_obj_as
Expand Down Expand Up @@ -75,7 +75,7 @@ def json_error_to_config_error(
# for what I suspect is the wrong reason.
def parse_and_validate_mapping(
config: Any,
model_type: TypeAlias,
model_type: Type[Model],
) -> Dict[str, Model]:
"""Parse `config` as a mapping from strings to a given `Model` type.
Args:
Expand All @@ -89,7 +89,7 @@ def parse_and_validate_mapping(
try:
# type-ignore: mypy doesn't like constructing `Dict[str, model_type]` because
# `model_type` is a runtime variable. Pydantic is fine with this.
instances = parse_obj_as(Dict[str, model_type], config)
instances = parse_obj_as(Dict[str, model_type], config) # type: ignore
except ValidationError as e:
raise ConfigError(str(e)) from e
return instances
3 changes: 2 additions & 1 deletion synapse/config/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
% MAIN_PROCESS_INSTANCE_MAP_NAME
)

# type-ignore: the expression `Union[A, B]` is not a Type[Union[A, B]] currently
self.instance_map: Dict[
str, InstanceLocationConfig
] = parse_and_validate_mapping(instance_map, InstanceLocationConfig)
] = parse_and_validate_mapping(instance_map, InstanceLocationConfig) # type: ignore

# Map from type of streams to source, c.f. WriterLocations.
writers = config.get("stream_writers") or {}
Expand Down

0 comments on commit 4c9de6f

Please sign in to comment.