mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
config: Throw if justknobs value is not a boolean (#139488)
This helps avoid an issue, where someone uses a mutable type that justknobs does not support within the code. And then it gets overriden to a different type Pull Request resolved: https://github.com/pytorch/pytorch/pull/139488 Approved by: https://github.com/ezyang
This commit is contained in:
committed by
PyTorch MergeBot
parent
040af3053a
commit
1d6ca50c5b
@ -11,7 +11,7 @@ from typing import Optional
|
||||
|
||||
from torch.testing._internal import fake_config_module as config
|
||||
from torch.testing._internal.common_utils import run_tests, TestCase
|
||||
from torch.utils._config_module import _UNSET_SENTINEL
|
||||
from torch.utils._config_module import _UNSET_SENTINEL, Config
|
||||
|
||||
|
||||
class TestConfigModule(TestCase):
|
||||
@ -329,6 +329,13 @@ torch.testing._internal.fake_config_module._save_config_ignore = ['e_ignored']""
|
||||
self.assertFalse(config.e_bool)
|
||||
self.assertTrue(config.e_bool)
|
||||
|
||||
def test_bad_jk_type(self):
|
||||
with self.assertRaises(
|
||||
AssertionError,
|
||||
msg="AssertionError: justknobs only support booleans, thisisnotvalid is not a boolean",
|
||||
):
|
||||
Config(default="bad", justknob="fake_knob")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
@ -71,6 +71,10 @@ class Config:
|
||||
self.env_name_default = env_name_default
|
||||
self.env_name_force = env_name_force
|
||||
self.value_type = value_type
|
||||
if self.justknob is not None:
|
||||
assert isinstance(
|
||||
self.default, bool
|
||||
), f"justknobs only support booleans, {self.default} is not a boolean"
|
||||
|
||||
|
||||
# Types saved/loaded in configs
|
||||
|
Reference in New Issue
Block a user