Skip to content

Commit

Permalink
Makes flax Modules more compatible with IPython auto-reload.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 712802399
  • Loading branch information
Flax Team committed Jan 7, 2025
1 parent dd70960 commit e2134af
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions flax/linen/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,11 @@ def __setattr__(self, name: str, val: Any):
object.__setattr__(self, name, val)
return
else:
# If the attribute is a python special method, we allow setting it (this
# is useful e.g. for IPython auto-reload).
if name.startswith('__'):
object.__setattr__(self, name, val)
return
# We're past all initialization and setup logic:
# Raises a TypeError just like frozen python dataclasses.
raise errors.SetAttributeFrozenModuleError(
Expand Down

0 comments on commit e2134af

Please sign in to comment.