Skip to content

Commit 4f271e5

Browse files
Update mixin.fielddomain del_construct for DH feedback
1 parent b988c04 commit 4f271e5

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

cf/mixin/fielddomain.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,32 +2484,30 @@ def del_construct(self, *identity, default=ValueError(), **filter_kwargs):
24842484
# have the concept of cyclic axes, so have to update the
24852485
# register of cyclic axes when we delete a construct in cf.
24862486

2487-
# Get the relevant key first because it will be lost upon deletion.
2487+
# Get the relevant key first because it will be lost upon deletion
24882488
key = self.construct_key(*identity, default=None, **filter_kwargs)
2489-
# Copy since should never change value of _cyclic attribute in-place
2490-
cyclic_axes = self._cyclic.copy()
2489+
cyclic_axes = self._cyclic
24912490

24922491
deld_construct = super().del_construct(
24932492
*identity, default=None, **filter_kwargs
24942493
)
24952494
if deld_construct is None:
24962495
if default is None:
24972496
return
2498-
2499-
return self._default(default, "Can't find unique construct to remove")
2497+
2498+
return self._default(
2499+
default, "Can't find unique construct to remove"
2500+
)
25002501

25012502
# If the construct deleted was a cyclic axes, remove it from the set
2502-
# of stored cyclic axes, to update that appropriately. Do this
2503-
# afterwards because the deletion might not be successful and don't
2504-
# want to update the cyclic() set unless we know the deletion occurred.
2503+
# of stored cyclic axes, to sync that. This is safe now, since given
2504+
# the block above we can be sure the deletion was successful.
25052505
if key in cyclic_axes:
2506-
# The below is to test that the construct was successfully deleted
2507-
if isinstance(default, Exception) or (
2508-
not isinstance(default, Exception)
2509-
and deld_construct != default
2510-
):
2511-
cyclic_axes.remove(key)
2512-
self._cyclic = cyclic_axes
2506+
# Never change value of _cyclic attribute in-place. Only copy now
2507+
# when the copy is known to be required.
2508+
cyclic_axes = cyclic_axes.copy()
2509+
cyclic_axes.remove(key)
2510+
self._cyclic = cyclic_axes
25132511

25142512
return deld_construct
25152513

0 commit comments

Comments
 (0)