KeyInfo: prevent read_only usage with can_disable, remove_value, absent_value, default, or required (#265)

* Prevent read_only usage with can_disable, remove_value, absent_value, default, or required.

* Add test.
This commit is contained in:
Felix Fontein 2024-03-03 09:03:25 +01:00 committed by GitHub
parent 84009262d0
commit 2ea1fef535
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -199,6 +199,8 @@ class KeyInfo(object):
raise ValueError('absent_value can not be combined with default, automatically_computed_from, can_disable=True, or absent_value')
if read_only and write_only:
raise ValueError('read_only and write_only cannot be used at the same time')
if read_only and any([can_disable, remove_value is not None, absent_value is not None, default is not None, required]):
raise ValueError('read_only can not be combined with can_disable, remove_value, absent_value, default, or required')
self.can_disable = can_disable
self.remove_value = remove_value
self.automatically_computed_from = automatically_computed_from