Repository: PrefectHQ/prefect

Issue:
Add is_skipped() method for states
Analogous to the methods for other major `State` types


Discussion:

Resolving patch:
diff --git a/src/prefect/engine/state.py b/src/prefect/engine/state.py
--- a/src/prefect/engine/state.py
+++ b/src/prefect/engine/state.py
@@ -102,6 +102,14 @@ def is_finished(self) -> bool:
         """
         return isinstance(self, Finished)
 
+    def is_skipped(self) -> bool:
+        """Checks if the object is currently in a skipped state
+
+        Returns:
+            - bool: `True` if the state is skipped, `False` otherwise
+        """
+        return isinstance(self, Skipped)
+
     def is_successful(self) -> bool:
         """Checks if the object is currently in a successful state
 
diff --git a/src/prefect/engine/task_runner.py b/src/prefect/engine/task_runner.py
--- a/src/prefect/engine/task_runner.py
+++ b/src/prefect/engine/task_runner.py
@@ -307,7 +307,7 @@ def check_upstream_skipped(
             State: the state of the task after running the check
         """
         if self.task.skip_on_upstream_skip and any(
-            isinstance(s, Skipped) for s in upstream_states_set
+            s.is_skipped() for s in upstream_states_set
         ):
             raise ENDRUN(
                 state=Skipped(
@@ -333,7 +333,9 @@ def check_task_trigger(
 
         Args:
             - state (State): the current state of this task
-            - upstream_states_set: a set containing the states of any upstream tasks.
+            - upstream_states_set (Set[State]): a set containing the states of any upstream tasks.
+            - ignore_trigger (bool): a boolean indicating whether to ignore the
+                tasks's trigger
 
         Returns:
             State: the state of the task after running the check
@@ -515,7 +517,7 @@ def cache_result(self, state: State, inputs: Dict[str, Any]) -> State:
         """
         if (
             state.is_successful()
-            and not isinstance(state, Skipped)
+            and not state.is_skipped()
             and self.task.cache_for is not None
         ):
             expiration = datetime.datetime.utcnow() + self.task.cache_for


Test patch:
diff --git a/tests/engine/test_state.py b/tests/engine/test_state.py
--- a/tests/engine/test_state.py
+++ b/tests/engine/test_state.py
@@ -179,6 +179,7 @@ def test_state_type_methods_with_pending_state(self):
         assert state.is_pending()
         assert not state.is_running()
         assert not state.is_finished()
+        assert not state.is_skipped()
         assert not state.is_successful()
         assert not state.is_failed()
 
@@ -187,6 +188,7 @@ def test_state_type_methods_with_scheduled_state(self):
         assert state.is_pending()
         assert not state.is_running()
         assert not state.is_finished()
+        assert not state.is_skipped()
         assert not state.is_successful()
         assert not state.is_failed()
 
@@ -195,6 +197,7 @@ def test_state_type_methods_with_running_state(self):
         assert not state.is_pending()
         assert state.is_running()
         assert not state.is_finished()
+        assert not state.is_skipped()
         assert not state.is_successful()
         assert not state.is_failed()
 
@@ -203,6 +206,7 @@ def test_state_type_methods_with_cached_state(self):
         assert state.is_pending()
         assert not state.is_running()
         assert not state.is_finished()
+        assert not state.is_skipped()
         assert not state.is_successful()
         assert not state.is_failed()
 
@@ -211,6 +215,7 @@ def test_state_type_methods_with_success_state(self):
         assert not state.is_pending()
         assert not state.is_running()
         assert state.is_finished()
+        assert not state.is_skipped()
         assert state.is_successful()
         assert not state.is_failed()
 
@@ -219,6 +224,7 @@ def test_state_type_methods_with_failed_state(self):
         assert not state.is_pending()
         assert not state.is_running()
         assert state.is_finished()
+        assert not state.is_skipped()
         assert not state.is_successful()
         assert state.is_failed()
 
@@ -227,6 +233,7 @@ def test_state_type_methods_with_trigger_failed_state(self):
         assert not state.is_pending()
         assert not state.is_running()
         assert state.is_finished()
+        assert not state.is_skipped()
         assert not state.is_successful()
         assert state.is_failed()
 
@@ -235,5 +242,6 @@ def test_state_type_methods_with_skipped_state(self):
         assert not state.is_pending()
         assert not state.is_running()
         assert state.is_finished()
+        assert state.is_skipped()
         assert state.is_successful()
         assert not state.is_failed()