-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: correct the model config types (#1183)
Corrects types related to the model configuration: * `LazyMapping` may have Boolean, integer, or float values, as well as strings * `_ConfigOption` may have a `secret` value for `type - also move this to [testing.py](ops/testing.py) since that's the only place it's used and it's private * `_ModelBackend.config_get` returns a dict with Boolean, integer, float, or string values The PR also sets a missing return type so that pyright would detect the `config_get` issue. There are no tests or pyright changes for the `_ConfigOption` change: we don't generally rely on pyright rather than unit tests for ensuring the typing is correct, but that doesn't seem feasible here. Let me know if you think we do need something added here to prevent regression. There are no tests or pyright changes for the `LazyMapping` change, other than making sure we do have [test_model.py](tests/test_model.py) exercise each of the config types. I don't think it's possible to have pyright detect this issue - e.g. you can get it to show an error if you try to use an integer config value as an integer (`self.config["int-opt"] + 1`), but that's still the case after the fix, since it could be a string (float, Boolean, secret) option. The test could have `typing.assert_type` calls but (a) that's only in Python 3.11, and (b) I'm not convinced we really want to do that. Let me know if you think we do need something added here to prevent regression. Fixes #1182
- Loading branch information
1 parent
d4a48fd
commit fa185b4
Showing
5 changed files
with
60 additions
and
25 deletions.
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
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