[config_types.Path] Add parents property

Also fix an unrelated warning.

Bug: 329113288
Change-Id: I38c590cde181045f395d55b6c98c550982b9a5f6
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/5450769
Commit-Queue: Rob Mohr <mohrr@google.com>
Reviewed-by: Chan Li <chanli@chromium.org>
Auto-Submit: Rob Mohr <mohrr@google.com>
diff --git a/recipe_engine/config_types.py b/recipe_engine/config_types.py
index ba5ac01..2589b35 100644
--- a/recipe_engine/config_types.py
+++ b/recipe_engine/config_types.py
@@ -7,7 +7,7 @@
 import itertools
 
 from dataclasses import dataclass, field
-from typing import ClassVar, TYPE_CHECKING
+from typing import ClassVar, Generator, TYPE_CHECKING
 
 if TYPE_CHECKING:
   from recipe_engine.internal.recipe_deps import RecipeModule, Recipe, RecipeRepo
@@ -259,6 +259,16 @@
     object.__setattr__(self, 'pieces', tuple(normalized_pieces))
 
   @property
+  def parents(self) -> Generator[Path, None, None]:
+    """For 'foo/bar/baz', yield 'foo/bar' then 'foo'."""
+    result: list[Path] = []
+    prev: Path = self
+    curr: Path = self.parent
+    while prev != curr:
+      yield curr
+      prev, curr = curr, curr.parent
+
+  @property
   def parent(self) -> Path:
     """For 'foo/bar/baz', return 'foo/bar'."""
     return Path(self.base, *self.pieces[0:-1])
diff --git a/recipe_modules/path/examples/full.py b/recipe_modules/path/examples/full.py
index a97c7a3..312b4d8 100644
--- a/recipe_modules/path/examples/full.py
+++ b/recipe_modules/path/examples/full.py
@@ -91,7 +91,7 @@
   assert api.path.split('abc/xyz') == ('abc', 'xyz')
   assert api.path.dirname('abc/xyz') == 'abc'
 
-  abc_def_xyz = api.path['tmp_base'] / 'abc.def.xyz'
+  abc_def_xyz = api.path.tmp_base_dir / 'abc.def.xyz'
   assert abc_def_xyz.stem == 'abc.def'
   assert abc_def_xyz.suffix == '.xyz'
   assert abc_def_xyz.suffixes == ['.def', '.xyz']
@@ -239,6 +239,11 @@
       f'foo{api.path.sep}bar{api.path.sep}baz.txt')
   assert separated_path.is_parent_of(slashy_file)
   assert api.path.is_parent_of(separated_path, slashy_file)
+  assert list(slashy_file.parents) == [
+      separated_path,
+      separated_path.parent,
+      api.path.start_dir,
+  ]
 
 
 def GenTests(api):