@@ -266,16 +266,20 @@ def save(self, *, include_default_values: Trilean = None, _log=True) -> None:
266266 self ._root .save (include_default_values = include_default_values , _log = _log )
267267 return
268268
269- # Determine whether the attributes that are involved in the path were changed
269+ # Determine whether the expected filepath of the file has changed (which
270+ # happens as a result of modifying attributes that compose the filename).
271+ # Note that this behaviour is gated behind rename=True flag.
270272 file_rename_required = False
271273 original_path = self .path
272- with hooks .disabled (): # hooks have to be disabled to prevent infinite loop
273- if "path" in self .__dict__ :
274- del self .__dict__ ["path" ] # invalidate the cached property
275274
276- # This call of self.path updates the value since the cache is invalidated
277- if self .path != original_path :
278- file_rename_required = True
275+ if self ._rename :
276+ with hooks .disabled (): # hooks have to be disabled to prevent infinite loop
277+ if "path" in self .__dict__ :
278+ del self .__dict__ ["path" ] # invalidate the cached property
279+
280+ # This call of self.path updates the value since the cache is invalidated
281+ if self .path != original_path :
282+ file_rename_required = True
279283
280284 if self .path :
281285 if self .exists and self ._frozen :
@@ -292,7 +296,7 @@ def save(self, *, include_default_values: Trilean = None, _log=True) -> None:
292296 text = self ._get_text (include_default_values = include_default_values )
293297
294298 write (self .path , text , display = True )
295- if file_rename_required :
299+ if self . _rename and file_rename_required :
296300 remove (original_path )
297301
298302 self .modified = False
0 commit comments