-
Notifications
You must be signed in to change notification settings - Fork 1
Fix usage of dict[str, Any] annotations. #6
Copy link
Copy link
Open
Description
dict[str, Any] annotations are potentially harmful as we forego type checking of data used as inputs to the various HTTP client methods.
For example:
mreg-api/mreg_api/models/abstracts.py
Lines 519 to 535 in 37facd6
| def patch(self, fields: dict[str, Any], validate: bool = True) -> Self: | |
| """Patch the object with the given values. | |
| Notes: | |
| ----- | |
| 1. Depending on the endpoint, the server may not return the patched object. | |
| 2. Patching with None may not clear the field if it isn't nullable (which few fields | |
| are). Odds are you want to pass an empty string instead. | |
| :param fields: The values to patch. | |
| :param validate: Whether to validate the patched object. | |
| :returns: The object refetched from the server. | |
| """ | |
| from mreg_api.client import MregClient # noqa: PLC0415 | |
| MregClient().patch(self.endpoint().with_id(self.id_for_endpoint()), **fields) |
Here, we may pass any data to MregClient.patch, which may result in an unhandled runtime exception when passing it unserializable data. We need to use Json, JsonMapping and QueryParams wherever we can in order to facilitate better type checking. Ideally we ban Any.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels