Created
September 13, 2022 09:51
-
-
Save thmsklngr/e1e136bf070d8c9da580f5ccd79f1bdb to your computer and use it in GitHub Desktop.
python-attrs - setting other attributes when one attribute is set
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
def _set_y(instance, attribute, value): | |
object.__setattr_(instance, 'y', value) | |
# returning a value is important, otherwise attribute will become None | |
return value | |
@define | |
class MyClass: | |
x: str = field(on_settattr=[_set_y]) | |
y: str = field() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment