@@ -741,20 +741,22 @@ def can_rollback(
741
741
transcription that precedes the current latest transcription, excluding any
742
742
transcriptions that are rollforwards or are sources of rollforwards.
743
743
744
- Returns:
745
- tuple:
746
- - (True, target, original) if a rollback is possible, where:
747
- * target is the transcription to roll back to.
748
- * original is the current latest transcription.
749
- - (False, reason, None) if a rollback is not possible, where:
750
- * reason is a string explaining why.
751
-
752
744
A rollback is only possible if:
753
- - There is more than one transcription.
754
- - There is a prior transcription that is not a rollforward
755
- or a source of one.
745
+ - There is more than one transcription.
746
+ - There is a prior transcription that is not a rollforward or source of one.
756
747
757
748
This method does not perform the rollback, only checks feasibility.
749
+
750
+ Returns:
751
+ result (tuple): A (bool, value, latest) tuple describing rollback
752
+ possibility.
753
+
754
+ Return Behavior:
755
+ - If no transcriptions exist: returns (False, reason_string, None).
756
+ - If no eligible rollback target exists: returns (False, reason_string,
757
+ None).
758
+ - If rollback is possible: returns (True, target_transcription,
759
+ latest_transcription).
758
760
"""
759
761
# original_latest_transcription holds the actual latest transcription
760
762
# latest_transcription starts by holding the actual latest transcription,
@@ -822,19 +824,21 @@ def rollback_transcription(self, user: User) -> Transcription:
822
824
as rolled back. It also updates the original latest transcription to reflect
823
825
that it has been superseded.
824
826
825
- Args:
826
- user (User): The user initiating the rollback.
827
-
828
- Returns:
829
- Transcription: The newly created rollback transcription.
830
-
831
- Raises:
832
- ValueError: If rollback is not possible (e.g. no eligible transcription).
827
+ If rollback is not possible, raises a `ValueError`.
833
828
834
829
The new transcription will:
835
830
- Have `rolled_back=True`.
836
831
- Set its `source` to the transcription it is rolled back to.
837
832
- Set `supersedes` to the current latest transcription.
833
+
834
+ Args:
835
+ user (User): The user performing the rollback.
836
+
837
+ Returns:
838
+ transcription (Transcription): The newly created rollback transcription.
839
+
840
+ Raises:
841
+ ValueError: If rollback is not possible due to invalid or missing history.
838
842
"""
839
843
results = self .can_rollback ()
840
844
if results [0 ] is not True :
@@ -878,21 +882,25 @@ def can_rollforward(
878
882
This checks whether the most recent transcription is a rollback transcription
879
883
and whether the transcription it replaced (its `supersedes`) can be restored.
880
884
881
- Returns:
882
- tuple:
883
- - (True, target, original) if rollforward is possible, where:
884
- * target is the transcription to roll forward to.
885
- * original is the current latest transcription.
886
- - (False, reason, None) if rollforward is not possible, where:
887
- * reason is a string explaining why.
888
-
889
885
This method handles cases where multiple rollforwards were applied,
890
886
walking backward through the transcription chain to find the appropriate
891
887
rollback origin.
892
888
893
889
A rollforward is only possible if:
894
- - The latest transcription is a rollback.
895
- - The rollback's superseded transcription exists and can be restored.
890
+ - The latest transcription is a rollback.
891
+ - The rollback’s superseded transcription still exists and can be restored.
892
+
893
+ This method does not perform the rollforward, only checks feasibility.
894
+
895
+ Returns:
896
+ result (tuple): A (bool, value, latest) tuple describing rollforward
897
+ possibility.
898
+
899
+ Return Behavior:
900
+ - If no transcriptions exist: returns (False, reason_string, None).
901
+ - If the rollback chain is malformed: returns (False, reason_string, None).
902
+ - If rollforward is possible: returns (True, target_transcription,
903
+ latest_transcription).
896
904
"""
897
905
# original_latest_transcription holds the actual latest transcription
898
906
# latest_transcription starts by holding the actual latest transcription,
@@ -999,23 +1007,34 @@ def rollforward_transcription(self, user: User) -> Transcription:
999
1007
"""
1000
1008
Perform a rollforward of the most recent rollback transcription.
1001
1009
1002
- This creates a new transcription that restores the text from the
1003
- rollback's superseded transcription and marks it as a rollforward.
1010
+ This creates a new transcription that restores the text from the rollback's
1011
+ superseded transcription and marks it as a rollforward. A rollforward is only
1012
+ possible if the latest transcription is a rollback and the replaced
1013
+ transcription still exists.
1014
+
1015
+ If rollforward is not possible, raises a `ValueError`.
1016
+
1017
+ The new transcription will:
1018
+ - Have `rolled_forward=True`.
1019
+ - Set its `source` to the transcription being rolled forward to.
1020
+ - Set `supersedes` to the current latest transcription.
1004
1021
1005
1022
Args:
1006
1023
user (User): The user initiating the rollforward.
1007
1024
1008
1025
Returns:
1009
- Transcription: The newly created rollforward transcription.
1026
+ transcription ( Transcription) : The newly created rollforward transcription.
1010
1027
1011
1028
Raises:
1012
- ValueError: If rollforward is not possible (e.g. no valid rollback
1013
- history or malformed transcription chain).
1014
-
1015
- The new transcription will:
1016
- - Have `rolled_forward=True`.
1017
- - Set its `source` to the transcription being rolled forward to.
1018
- - Set `supersedes` to the current latest transcription.
1029
+ ValueError: If rollforward is not possible, such as when no rollback
1030
+ exists or the history is malformed.
1031
+
1032
+ Return Behavior:
1033
+ - If rollforward is possible:
1034
+ - Creates a new transcription restoring the original text.
1035
+ - Marks it with `rolled_forward=True`.
1036
+ - If rollforward is not possible:
1037
+ - Raises `ValueError` with a descriptive message.
1019
1038
"""
1020
1039
results = self .can_rollforward ()
1021
1040
if results [0 ] is not True :
0 commit comments