Skip to content

Commit

Permalink
Alias: deepcopy fallback before returning.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwardrop committed Aug 16, 2024
1 parent 0c0ceec commit cf3c3a5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spec_classes/types/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class Alias:
attribute.
fallback: An optional default value to return if the attribute being
aliased does not yet have a value (otherwise any errors retrieving
the underlying aliased attribute value are passed through).
the underlying aliased attribute value are passed through). Note
that this fallback is deepcopied before being returned to prevent
accidental mutations.
"""

ATTR_PARSER = re.compile(
Expand Down Expand Up @@ -125,7 +127,9 @@ def __get__(self, instance: Any, owner=None):
)
except AttributeError:
if self.fallback is not MISSING:
return self.fallback
from spec_classes.utils.mutation import protect_via_deepcopy

return protect_via_deepcopy(self.fallback)
raise
except RecursionError as e:
raise ValueError(
Expand Down

0 comments on commit cf3c3a5

Please # to comment.