@@ -2484,32 +2484,30 @@ def del_construct(self, *identity, default=ValueError(), **filter_kwargs):
2484
2484
# have the concept of cyclic axes, so have to update the
2485
2485
# register of cyclic axes when we delete a construct in cf.
2486
2486
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
2488
2488
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
2491
2490
2492
2491
deld_construct = super ().del_construct (
2493
2492
* identity , default = None , ** filter_kwargs
2494
2493
)
2495
2494
if deld_construct is None :
2496
2495
if default is None :
2497
2496
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
+ )
2500
2501
2501
2502
# 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.
2505
2505
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
2513
2511
2514
2512
return deld_construct
2515
2513
0 commit comments