Skip to content

Commit

Permalink
Validate the dataclass is frozen when allow_unfrozen=True (Fix #406)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 572257669
  • Loading branch information
Conchylicultor authored and The etils Authors committed Oct 10, 2023
1 parent ea1f487 commit a7e91dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Changelog follow https://keepachangelog.com/ format.

## [Unreleased]

* `edc`:
* Changed: Raise an error if `allow_unfrozen=` is used on a non-frozen
dataclass

## [1.5.0] - 2023-09-19

* `ecolab`:
Expand Down
5 changes: 5 additions & 0 deletions etils/edc/frozen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

def add_unfrozen(cls: _Cls) -> _Cls:
"""Add the `frozen`, `unfrozen` methods."""
if not cls.__dataclass_params__.frozen:
raise ValueError(
'allow_unfrozen require the dataclass to be defined with'
f' `frozen=True`. For {cls}'
)
cls_frozen = getattr(cls, 'frozen', None)
cls_unfrozen = getattr(cls, 'has_unfrozen', None)

Expand Down

0 comments on commit a7e91dc

Please sign in to comment.